title: How to select all in PrimeFaces TreeTable?
body: <p>I have a PrimeFaces tree table and would like to add a check box which allows the user to select/unselect all.</p>
  
  <p>Here is an extract from my xhtml</p>
  
  <pre><code>&lt;p:selectBooleanCheckbox
          itemLabel="Select all"                                      
          value="#{mainViewBean.selectAll}"&gt;
          &lt;p:ajax listener="#{mainViewBean.onSelectAll}"
              update="@this :mainForm" /&gt;
      &lt;/p:selectBooleanCheckbox&gt;  
  
      &lt;p:treeTable id="treeToAssign"
          value="#{mainViewBean.treeValue}" var="vh"
          selectionMode="checkbox"
          selection="#{mainViewBean.treeSelection}"&gt;
          &lt;f:facet name="header"&gt;
              Tree Table                                                  
          &lt;/f:facet&gt;                                                              
          &lt;p:column&gt;                                      
              &lt;h:outputText value="#{vh.name}" /&gt;
          &lt;/p:column&gt;                                 
      &lt;/p:treeTable&gt;
  </code></pre>
  
  <p>and here is my bean method</p>
  
  <pre><code>private TreeNode treeValue;
  private TreeNode[] treeSelection;
  private boolean selectAll;
  
  public void onSelectAll() {             
      List&lt;TreeNode&gt; selection = new ArrayList&lt;&gt;();
      for (TreeNode node : treeValue.getChildren()) {
      node.setSelected(selectAll);
          selection.add(node);
      }
  
      treeSelection = selection.toArray(new TreeNode[selection.size()]);
  }
  </code></pre>
  
  <p>I had initially tried just setting <code>NODE.setSelected(selectAll);</code>, but that didn't work so I tried manually manually filling <code>treeSelection</code> as well.</p>
  
  <p>I feel like this should be straightforward, but have been unable to figure it out, any suggestions?</p>
  
  <p>Thanks</p>