Home >Web Front-end >JS Tutorial >How to Pass Parameters to p:remoteCommand in JavaScript (PrimeFaces 3.3 )

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

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-24 16:01:02748browse

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>

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>

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

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

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>

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>

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>

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!

Statement:
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