【问题标题】:get TreeNode from jsf page从 jsf 页面获取 TreeNode
【发布时间】:2014-08-23 16:19:26
【问题描述】:

我在我的代码中自定义了一个 Tree primefaces 组件,这是包含我的 treeNodes 的这个 jsf 页面的代码:

<h:form id="formNode">
                        <p:commandButton value="+Add"  oncomplete="PF('w_addRoot').show();" />

                        <p:tree value="#{treeManagedBean.root}" var="node" animate="true" dynamic="true"
                                selection="#{treeManagedBean.selectedNode}" selectionMode="single"
                                 >
                            <p:treeNode expandedIcon="ui-icon ui-icon-folder-open"
                                        collapsedIcon="ui-icon ui-icon-folder-collapsed">
                                <h:panelGrid style="margin-top: -9px;" columns="2" >
                                    <h:outputText value="#{node}"/>
                                    <p:commandButton action="#{treeManagedBean.createNodeHere}" icon="iconForkTree" style="margin-top: 5px; margin-left:30px; max-width: 15px; max-height: 15px;">
                                        <f:setPropertyActionListener target="#{treeManagedBean.currNodeName}" value="#{node}" />
                                    </p:commandButton>    

                                </h:panelGrid>

                            </p:treeNode>
                            <p:treeNode type="document" icon="ui-icon ui-icon-document">
                                <h:link value="#{node}"/>
                            </p:treeNode>

                            <p:ajax event="select" listener="#{treeManagedBean.onNodeSelect}"></p:ajax>
                            <p:ajax event="unselect" listener="#{treeManagedBean.onNodeUnSelect}"></p:ajax>
                            <p:ajax event="expand" listener="#{treeManagedBean.onNodeExpand}"></p:ajax>
                            <p:ajax event="collapse" listener="#{treeManagedBean.onNodeCollapse}"></p:ajax>
                        </p:tree>
                    </h:form>

这里是 managedBean 中应该创建子节点的函数:

public void createNodeHere(){
        System.out.println("current node Name :  "+currNodeName);
        // get the current node from the giving name currNodeName
        currNodeName="";
    }

所以我想在用户单击命令按钮(带有加号图标)时创建一个子 treeNode,并且这个子 treeNode 的父节点应该是当前节点。问题是我无法获取当前节点(我只得到它的名称)。那么我可以从它的名称中获取 treeNode 对象吗?如果没有,有一种方法可以在不使用事件的情况下做到这一点(选择、取消选择...)

请注意,使用带有事件属性的 f:ajax 标记(选择、展开、折叠、取消选择)我可以获得当前节点,但这不是我的目标。

【问题讨论】:

    标签: jsf primefaces treenode


    【解决方案1】:

    我创建了解决方案,所以我所做的是将当前节点的名称传递给我的 managedBean,然后我得到所有节点的列表(所有存在的节点的 listeOFNoeud 列表)并在创建的函数中节点:

    public void createNewRoot(ActionEvent event) {
    
            System.out.println("---------------------- Create Node -----------------------");
            System.out.println("name of the child " + nameOfTreeNode + "\n Name of the parent : " + nameOfParent);
            TreeNode t=new DefaultTreeNode();
            for (TreeNode treeNode : listeOFNoeud) {
                if(nameOfParent.equals(treeNode.getData().toString())){
                    t=new DefaultTreeNode(nameOfTreeNode, treeNode);
                }
            }
            listeOFNoeud.add(t);
            System.out.println("Node Added");
        }
    

    nameOfTreeNode :将要创建的子节点的名称。

    nameOfParent:当前节点的名称(子节点的父节点)。

    【讨论】:

      猜你喜欢
      • 2017-08-17
      • 2013-04-17
      • 2011-09-28
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多