我想将参数node传递给函数doAction,该函数将被远程命令调用,如何传递?假设node有属性name和type,我想在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"
}
最佳答案
我解决了这个问题
<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
...
}
关于jsf - 如何将参数传递给树表中的远程命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371806/