Visualizing data with tree
The tree
component visualizes hierarchical data in the tree format.
How to do it…
The data for tree
is provided as instances of org.primefaces.model.TreeNode
, which correspond to the nodes in the tree. A pure client-side tree might be useful to create tree-based navigation menus. A basic data model for a tree could be constructed as follows:
TreeNode root = new DefaultTreeNode("Root", null); TreeNode node1 = new DefaultTreeNode("Node1", root); TreeNode node2 = new DefaultTreeNode("Node2", root); TreeNode node11 = new DefaultTreeNode("Node1.1", node1); TreeNode node12 = new DefaultTreeNode("Node1.2", node1); TreeNode node21 = new DefaultTreeNode("Node2.1", node2); TreeNode node211 = new DefaultTreeNode("Node2.1.1", node21);
The definition of tree
for the previously mentioned model will be as shown here:
<p:tree id="simple" value="#{treeDataBean.root}" var="node"> <p:treeNode> <h:outputText value="#{node}" /> </p:treeNode> </p:tree>...