Primefaces p:remoteCommand 参数始终为空 [英] Primefaces p:remoteCommand parameter always null
问题描述
我正在尝试使用
p:远程命令
不幸的是,当我在 bean 方法中检索参数时,我总是得到 null.
Unfortunately when I retrieve the paramer in my bean method I always get null.
我的代码有问题吗?
这是我的页面代码:
<a href="#" onclick="rc([{'d':'01'}])">01</a>
<p:remoteCommand name="rc" update=":myform:messages" actionListener="#{mybean.changedaybar}" />
这是bean方法:
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."));
}
推荐答案
您使用的是哪个 PrimeFaces 版本?这很重要,因为从 JavaScript 函数向 p:remoteCommand
传递参数的方式在 PrimeFaces 3.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.
您将在以下帖子中看到正确的语法:https://stackoverflow.com/a/18510102/2118909 但为了您的方便,这里是摘要.
You will see the correct syntax in the following post: https://stackoverflow.com/a/18510102/2118909 but for your convenience here is the summary.
来自 PrimeFaces 3.3
From PrimeFaces 3.3
传递参数
远程命令可以通过以下方式发送动态参数;
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>
在 PrimeFaces 3.3 之前
Before PrimeFaces 3.3
传递参数
远程命令可以通过以下方式发送动态参数;
Remote command can send dynamic parameters in the following way;
increment({param1:'val1', param2:'val2'});
<a href="#" onclick="rc({d:'01'})">01</a>
这篇关于Primefaces p:remoteCommand 参数始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!