我想将参数节点传递给远程命令将调用的函数 doAction ,我该如何传递它?假设节点具有属性名称和类型,我想在doAction中使用它们,我该如何传递变量?
谢谢!
public static class node {
String name;
String type;
//setters getters etc...
}
<p:remoteCommand name="doWhatYouWant" action="#{managedBean.doAction}" />
<p:treeTable value="#{managedBean.tree}" var="node">
<p:column>
<p:commandLink value="Invoke action" onclick="doWhatYouWant([params...])" />
</p:column>
</p:tree>
public void doAction() {
// do something with var="node"
}
答案 0 :(得分:5)
我用
解决了这个问题 <p:remoteCommand name="doWhatYouWant" action="#{managedBean.doAction}" />
...
<p:commandLink value="Invoke action"
onclick="doWhatYouWant(
[{name:'n', value:'#{node.name}'},
{name:'t', value:'#{node.type}'}])" />
在支持bean中:
public void doAction() {
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> map = context.getExternalContext().getRequestParameterMap();
String name = map.get("n"); // name attribute of node
String type = map.get("t"); // type attribute of node
...
}