Primefaces p:remoteCommand parameter always null

5.6k views Asked by At

I am trying to pass a parameters with

p:remoteCommand

Unfortunately when I retrieve the paramer in my bean method I always get null.

Is there anything wrong with my code?

Here is my page code:

<a href="#" onclick="rc([{'d':'01'}])">01</a>

<p:remoteCommand name="rc" update=":myform:messages" actionListener="#{mybean.changedaybar}" />

and this is the bean method:

public void changedaybar() {
            Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
            String param = params.get("d");

            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Executed"+param, "Using RemoteCommand."));
    }
1

There are 1 answers

4
Mathieu Castets On BEST ANSWER

Which PrimeFaces version are you using? It's important because the way to pass parameters from a JavaScript function to a p:remoteCommand has changed in PrimeFaces 3.3.

You will see the correct syntax in the following post: https://stackoverflow.com/a/18510102/2118909 but for your convenience here is the summary.

From PrimeFaces 3.3

Passing Parameters

Remote command can send dynamic parameters in the following way;

increment([{name:'x', value:10}, {name:'y', value:20}]);

<a href="#" onclick="rc([{name: 'd', value:'01'}])">01</a>

Before PrimeFaces 3.3

Passing Parameters

Remote command can send dynamic parameters in the following way;

increment({param1:'val1', param2:'val2'});

<a href="#" onclick="rc({d:'01'})">01</a>