Visualizing data with tree
The tree
component visualizes hierarchical data in tree
format.
How to do it...
The data for the tree
is provided with 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 the tree will be as follows:
<p:tree value="#{treeDataController.root}" var="node"> <p:treeNode> <h:outputText value="#{node}" /> </p:treeNode> </p:tree>
This will be visualized as follows: