title: How to create p:treeNode with arbitrary components based on arbitrary node data objects
body: <p>Assue I have a class <code>DataObj</code></p>
  
  <pre><code>public class DataObj implements Serializable {
    private Set&lt;String&gt; values;
    private String name;
  
    // default constructor, constructor to pass properties
  
    // getter and setter
  }
  </code></pre>
  
  <p>and set an instance as data property of a <code>TreeNode</code>:</p>
  
  <pre><code>@ManagedBean
  public ACtrl extends Serializable {
    private TreeNode root = new DefaultTreeNode(new DataObj(new HashSet&lt;&gt;(Arrays.asList("a","b")), "some name"));
  
    // default constructor
  
    // getter for root
  }
  </code></pre>
  
  <p>How can I create dynamic <code>p:treeNode</code>s which contain components based on the data property (and it's content), e.g. a checkbox for each string in <code>DataObj.values</code>? </p>
  
  <p>The following example shows how to change content based on the type or value of <code>TreeNode.data</code>, but <code>c:if</code> and <code>c:forEach</code> don't work (I'm very sure they aren't supposed to because node should be <code>null</code> when they're evaluated):</p>
  
  <pre><code>&lt;ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://primefaces.org/ui"  &gt;
    &lt;h:form id="form"&gt;
      &lt;p:tree id="tree" value="#{aCtrl.root}" var="node" &gt;
        &lt;p:treeNode id="treeNode"&gt;
          &lt;h:outputText value="#{node.name}"/&gt;
          &lt;p:spinner value="#{node}" rendered="#{node.getClass().getName() eq 'java.lang.Integer'}"/&gt;
          &lt;c:if test="#{node.getClass().getName() eq 'DataObj'}"&gt;
            &lt;c:forEach items="#{node.values}" var="value"&gt;
              &lt;h:selectBooleanCheckbox value="#{value}"/&gt;
              &lt;h:outputText value="#{value.name}"/&gt;
            &lt;/c:forEach&gt;
          &lt;/c:if&gt;
        &lt;/p:treeNode&gt;
      &lt;/p:tree&gt;  
    &lt;/h:form&gt;  
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>Please consider this pseudo code... I'm aware that it doesn't run or compile, but it eases the explanation of my problem and possibly the answers :)</p>
  
  <p>Do alternative JSF component libraries or extensions exist to solve this?</p>