For passing paramters from JS to p:remoteCommand
(provided by primefaces), you can use this:
remoteCommandFunctionName({name1:'value1', name2:'value2'});
After that, how do you receive this set of parameters in remoteCommand
for sending it to backing beans?
Shamelessly plug my answer because it costs me hours to solve this problem in PrimeFace 3.3. The solution is to pass your arguments as an array of {name: <param-name>, value: <param-value>}.
As in Neyko's answer, the invocation should be changed to:
remoteCommandFunctionName([{name: 'name1', value: 'value1'}, {name: 'name2', value: 'value2'}]);
If you have defined remote command like this:
<p:remoteCommand name="remoteCommandFunctionName"
actionListener="#{myBean.exec}"/>
And you have a Javascript method call with parameters:
remoteCommandFunctionName({name1:'value1', name2:'value2'});
You don't need to specify parameters passed to Javascript method call into remoteCommand. I think that you'll need these parameters in the backing bean after all. You can use the request parameters map to obtain the values for the parameters passed in the JavaScript call in the backing bean method:
public void exec() {
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String name1 = (String) map.get("name1");
String name2 = (String) map.get("name2");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With