Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pass parameters(from javascript) into remoteCommand(& then send it to backing beans)? [duplicate]

Tags:

jsf

primefaces

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?

like image 996
Rajat Gupta Avatar asked Sep 21 '11 09:09

Rajat Gupta


2 Answers

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'}]);
like image 52
instcode Avatar answered Nov 02 '22 05:11

instcode


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");
}
like image 17
Neyko Avatar answered Nov 02 '22 06:11

Neyko