Home >Web Front-end >JS Tutorial >How to Pass Parameters to p:remoteCommand in JavaScript (PrimeFaces 3.3 )
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>
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>
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>
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!