PrimeFaces Tree component, setting selected node from managed bean

前端 未结 7 2280
南旧
南旧 2020-12-18 20:27

I\'m running Primefaces 3.2 and JSF 2.0 on Glassfish 3.

I\'ve tried a lot, to programatically set the selected node from a managed bean. That includes setting the se

7条回答
  •  自闭症患者
    2020-12-18 20:59

    I solved it using:

    node.setSelected(true);
    

    I discovered that selecting the node is not enough for the "tree component" to expand from root node to selected node.

    For this, I used the following approach. On the view :

     
    

    on the java code:

    public void onExpand(NodeExpandEvent event) {
        expand(event.getTreeNode());
    }
    
    private void expand(TreeNode treeNode){
        if (treeNode.getParent()!=null){
            treeNode.getParent().setExpanded(true);
            expand(treeNode.getParent());
        }
    }
    

提交回复
热议问题