Question:
Is it possible to pass values to the p:remoteCommand component from JavaScript? If so, how can these values be received in the backing bean?
Answer:
Yes, passing parameters to p:remoteCommand from JavaScript is possible. The approach depends on the PrimeFaces version being used.
For PrimeFaces 3.3 and newer, use the following syntax:
increment([{name:'x', value:10}, {name:'y', value:20}]);
This allows for multiple values with the same parameter name. Parameters with single values can be accessed in the backing bean as request-scoped properties:
@ManagedProperty("#{param.x}") private int x; @ManagedProperty("#{param.y}") private int y;
For PrimeFaces 3.2 or older, use the following syntax:
increment({param1:'val1', param2:'val2'});
These parameters can be accessed in the backing bean using the RequestParameterMap:
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); String param1 = params.get("param1"); String param2 = params.get("param2");
To pass parameters with multiple values, use the following syntax (PrimeFaces 3.3 or newer):
functionName([{name:'foo', value:'one'}, {name:'foo', value:'two'}, {name:'foo', value:'three'}]);`
This can be accessed in the backing bean as a managed property with the paramValues attribute:
@ManagedProperty("#{paramValues.foo}") private String[] foos;
The above is the detailed content of How to Pass Parameters to p:remoteCommand from JavaScript?. For more information, please follow other related articles on the PHP Chinese website!