如何将树添加到bean中的tab

时间:2012-04-16 03:08:25

标签: jsf tabs tree primefaces

我尝试将树添加到1个标签:

Tab tmp = new Tab();
TreeNode root = new  DefaultTreeNode("root",null);
TreeNode test = new DefaultTreeNode("test",root);
tmp.getChildren().add((UIComponent)root);

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我建议您使用Accordion Panel - Model

  

Accordion可以显示模型支持的动态标签数量。由于标签是即时生成的,因此很容易实现添加/删除标签。

看看这个例子...... INMO就像你应该实现你的任务一样...(更容易,以及它在展示中实现它的方式)

展开给定的例子试试

添加到标签

<p:tree value="#{player.root}" var="node" id="tree">  
    <p:treeNode id="treeNode">  
        <h:outputText value="#{node}" id="lblNode"/>  
    </p:treeNode>  
</p:tree> 

并添加到播放器类......

private TreeNode root;  

public initTree() {  
    root = new DefaultTreeNode("Root", null);  
    TreeNode node0 = new DefaultTreeNode("Node 0", root);  
    TreeNode node1 = new DefaultTreeNode("Node 1", root);  
    TreeNode node2 = new DefaultTreeNode("Node 2", root);  

    TreeNode node00 = new DefaultTreeNode("Node 0.0", node0);  
    TreeNode node01 = new DefaultTreeNode("Node 0.1", node0);  

    TreeNode node10 = new DefaultTreeNode("Node 1.0", node1);  
    TreeNode node11 = new DefaultTreeNode("Node 1.1", node1);  

    TreeNode node000 = new DefaultTreeNode("Node 0.0.0", node00);  
    TreeNode node001 = new DefaultTreeNode("Node 0.0.1", node00);  
    TreeNode node010 = new DefaultTreeNode("Node 0.1.0", node01);  

    TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);  
}  

public TreeNode getRoot() {  
    return root;  
}  

这是player.java的来源

Player.java

修改

看着之后 Issue with p:tree inside loops (ui:repeat, p:dataTable, ...)

Issue 3640: NullPointerException during state saving with p:tree inside loops (ui:repeat, p:tabView, ...)

似乎有关于此功能的公开错误...