title: Generate primefaces ajax tree on demand?
body: <p>I have a project using JSF primefaces and EJB managed Beans with hibernate storage.
   <a href="http://www.primefaces.org/showcase/ui/treeAjax.jsf" rel="nofollow">http://www.primefaces.org/showcase/ui/treeAjax.jsf</a></p>
  
  <p>Question: I keep on getting a out of memory or stack overflow errors can you see a problem with my recursion?</p>
  
  <pre><code>@ManagedBean(name = "categoryController")
  @RequestScoped
  public class CategoryController implements Serializable {
      ...
  
      @EJB
      private CategoryFacade ejbFacade;
      private TreeNode root;
  
      public TreeNode getRoot() {
          return root;
      }
  
      @PostConstruct
      public void init() {
          root = new DefaultTreeNode("Root", null);
          System.out.print("Facade value=" + getFacade());
          Category categoryRoot = getFacade().find(new Integer(1));
          getSubcategories(categoryRoot, root);
  
      }
  
      private void getSubcategories(Category categoryRoot, TreeNode root) {
          List&lt;Category&gt; list = getFacade().findByNamedQuery("Category.findByPCatid", "pcatid", categoryRoot);
          Iterator&lt;Category&gt; it = list.iterator();
          while (it.hasNext()) {
              Category subcategory = it.next();
              TreeNode nextNode = new DefaultTreeNode(subcategory.getUcatid(), root);
              getSubcategories(subcategory, nextNode);
  
          }
  
      }
  
      ...
  }
  </code></pre>