In this scenario, you seek to pass values to your p:remoteCommand from JavaScript. Here's how it can be achieved, depending on your PrimeFaces version:
Since version 3.3, the syntax has evolved. As per the PrimeFaces user guide, here's how to pass parameters:
<code class="javascript">increment([{name:'x', value:10}, {name:'y', value:20}]);</code>
In the backing bean, access these parameters through the @ManagedProperty annotation:
<code class="java">@ManagedProperty("#{param.x}") private int x; @ManagedProperty("#{param.y}") private int y;</code>
Before version 3.3, the syntax was different:
<code class="javascript">increment({param1:'val1', param2:'val2'});</code>
Retrieval of these parameters in the backing bean remains the same as described above.
Alternatively, you can fetch parameters using FacesContext in a broader scoped bean:
<code class="java">Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); int x = Integer.valueOf(params.get("x")); int y = Integer.valueOf(params.get("y"));</code>
For passing multiple values to a single parameter, use the following syntax:
<code class="javascript">functionName([{name:'foo', value:'one'}, {name:'foo', value:'two'}, {name:'foo', value:'three'}]);</code>
Access these values in the backing bean using @ManagedProperty or FacesContext:
<code class="java">@ManagedProperty("#{paramValues.foo}") private String[] foos;</code>
The above is the detailed content of How to Pass Parameters to p:remoteCommand from JavaScript in PrimeFaces?. For more information, please follow other related articles on the PHP Chinese website!