title: How to create a dynamic tree?
body: <p>I´m having some trouble implementing a dynamic tree structure using the primefaces tree implementation. In the showcase provided by primeface, the structure of the code is like below. This is however very static. I´m trying to figure out how I could do this with data fetched from a database, where the depth of the tree would be unknown at compile time. </p>
  
  <p>I`m thinking that I probabply need some recursive method to implement this, but I cannot quite get my head around what the implementation would look like.</p>
  
  <p>Any thoughts?</p>
  
  <p>Below is the example code from primefaces </p>
  
  <pre><code>private TreeNode root;
  private TreeNode selectedNode;
  
  public TreeBean() {
      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);
  }
  </code></pre>