如何在treetable中将参数传递给远程命令?

时间:2013-06-28 19:00:02

标签: jsf primefaces

我想将参数节点传递给远程命令将调用的函数 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"
}

1 个答案:

答案 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  
    ...
}