title: Primefaces TreeNode deleted at second action
body: <p>In my jsf page I have a <code>&lt;p:treeTable&gt;</code> structure. I am trying to delete a node when clicking on a small icon placed on one of the columns:</p>
  
  <pre><code>&lt;p:column rendered="#{node.isLeaf}"  style="width:70px"&gt;  
       &lt;p:commandLink  styleClass="entity-icon"  update=":clipboard-tree" ajax="true"
                            action="#{clipboardManager.removeClipboard(node)}" &gt;
         &lt;p:graphicImage value="/resources/images/delete.png" styleClass="entity-icon-tree"/&gt;
      &lt;/p:commandLink&gt;
   &lt;/p:column&gt;
  </code></pre>
  
  <p>And my removeClipboard function looks something like this:</p>
  
  <pre><code>public void removeClipboard(FindResult result){
    TreeNode node = result.getNode(); 
  
    node.getChildren().clear();  
    node.getParent().getChildren().remove(node);  
  
    node.setParent(null);  
    node = null;  
  
  }
  </code></pre>
  
  <p>This is similar to the showcase offered by primefaces. However the tree get's updated only on the second click and I get the following exception:</p>
  
  <pre><code>[Index: 0, Size: 0] with root cause java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  </code></pre>
  
  <p>This happens only when I try to delete the last child of a node.
  Does anybody have an idea why this is happening? Or how I can fix it? 
  Thank you in advance.</p>