Primefaces p:remoteCommand parameter always null [duplicate]

不羁的心 提交于 2019-12-24 17:56:00

问题


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:


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>


来源:https://stackoverflow.com/questions/30775175/primefaces-premotecommand-parameter-always-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!