1

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."));
    }
Gyonder
  • 3,674
  • 7
  • 32
  • 49

1 Answers1

3

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>
Community
  • 1
  • 1
Mathieu Castets
  • 5,861
  • 3
  • 28
  • 37
  • I am using 5.2. Anyway your example was useful. – Gyonder Jun 11 '15 at 08:33
  • Please just mark it as a duplicate if it is... – Kukeltje Jun 11 '15 at 09:01
  • I don't think it is. My question was referrred to a particular case. The answered really helped me contrary to the other one, which I had seen but didn't find useful. – Gyonder Jun 11 '15 at 13:54
  • Hmmmm imo it contians all relevant information. Maybe you did not understand the relation. As posted in the answer, it is a summary of that other post, but yes in the context of your question. – Kukeltje Jun 11 '15 at 15:02