Class Code:

import java.io.Serializable; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import org.primefaces.model.DefaultTreeNode; import org.primefaces.model.TreeNode; @ManagedBean(name="treeBasicView") @ViewScoped public class BasicView implements Serializable { private TreeNode root; @PostConstruct public void init() { root = new DefaultTreeNode("Root", null); TreeNode node0 = new DefaultTreeNode("Node 0", root); TreeNode node1 = new DefaultTreeNode("Node 1", 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); node1.getChildren().add(new DefaultTreeNode("Node 1.1")); node00.getChildren().add(new DefaultTreeNode("Node 0.0.0")); node00.getChildren().add(new DefaultTreeNode("Node 0.0.1")); node01.getChildren().add(new DefaultTreeNode("Node 0.1.0")); node10.getChildren().add(new DefaultTreeNode("Node 1.0.0")); root.getChildren().add(new DefaultTreeNode("Node 2")); } public TreeNode getRoot() { return root; } } 

Page code:

 <h:form> <h3 style="margin-top:0">Client</h3> <p:tree value="#{treeBasicView.root}" var="node"> <p:treeNode> <h:outputText value="#{node}" /> </p:treeNode> </p:tree> <h3>Ajax</h3> <p:tree value="#{treeBasicView.root}" var="node" dynamic="true"> <p:treeNode> <h:outputText value="#{node}" /> </p:treeNode> </p:tree> </h:form> 

At startup, it simply gives three points:

.

.

.

I can not understand why. And a great mystery is: value = "# {node}" What is a node? Where does he pull the values?

  • one
    H.z. what a point. Maybe some mistakes besides the tree. And # {node} is the current node, or rather, the data put in the tree node. It is taken from var = "node". This is how the iterator variable is set, which can be referenced in the components, which should somehow represent these nodes. - Sergey
  • one
    Your code is fully functional - copied and launched at home, everything is OK, I see two trees, there are names, the nodes are correctly deployed. From the above code it is not clear what you have outside the form, perhaps there is a problem there. Try to “shorten” the contents of the page as much as possible, leaving only <h: head />, <h: body> and <f: view> on the page. - bobzer

0