Home > Web Front-end > JS Tutorial > body text

How to Pass Parameters to p:remoteCommand in JavaScript (PrimeFaces 3.3 )

Mary-Kate Olsen
Release: 2024-10-24 16:01:02
Original
632 people have browsed it

How to Pass Parameters to p:remoteCommand in JavaScript (PrimeFaces 3.3 )

Passing Parameters to p:remoteCommand from JavaScript

PrimeFaces 3.3 or Newer

PrimeFaces 3.3 introduces a new syntax for passing parameters to p:remoteCommand:

<code class="javascript">increment([{name:'x', value:10}, {name:'y', value:20}]);</code>
Copy after login

This syntax allows you to pass multiple values for the same parameter name. For example, you could have the following JavaScript code:

<code class="javascript">functionName([{name:'foo', value:'one'}, {name:'foo', value:'two'}, {name:'foo', value:'three'}]);</code>
Copy after login

In your backing bean, you could access these parameters using the following annotations:

<code class="java">@ManagedProperty("#{paramValues.foo}")
private String[] foos;</code>
Copy after login

PrimeFaces 3.2 or Older

For PrimeFaces 3.2 and older, the syntax for passing parameters to p:remoteCommand is as follows:

<code class="javascript">increment({param1:'val1', param2:'val2'});</code>
Copy after login

In your backing bean, you could access these parameters using the following annotations:

<code class="java">@ManagedProperty("#{param.param1}")
private String param1;

@ManagedProperty("#{param.param2}")
private String param2;</code>
Copy after login

Note

In all cases, you can also access the parameters using the FacesContext object:

<code class="java">Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String param1 = params.get("param1");
String param2 = params.get("param2");</code>
Copy after login

Related Articles

  • [Dependency Inject Request Parameter with CDI and JSF2](https://www.primefaces.org/docs/javascript/dependency_injection.html)
  • [How to Invoke a JSF Managed Bean on a HTML DOM Event Using Native JavaScript?](https://www.primefaces.org/docs/javascript/jsf_behavior_in_js.html)

The above is the detailed content of How to Pass Parameters to p:remoteCommand in JavaScript (PrimeFaces 3.3 ). For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!