title: Primefaces TreeTable: Deleting node using p:ajax not work
body: <p>I'm trying to create a treeTable component(PrimeFaces 3.5) which when it happens the unselect ajax event(uncheck the box), I want to delete this unselected(Unchecked) treeNode, using the onNodeUnselect listener method: </p>
  
  <p><strong>XHTML</strong></p>
  
  <pre><code>&lt;p:treeTable id="treeTable" value="#{treeTableManager.treeNode}" var="data" 
               selection="#{treeTableManager.selectedTreeNode}"
               selectionMode="checkbox"&gt;
      &lt;p:ajax event="unselect" update=":form:treeTable" listener="#{treeTableManager.onNodeUnselect}" /&gt;
      &lt;p:column&gt;
          &lt;f:facet name="header"&gt;
              Title
          &lt;/f:facet&gt;
          &lt;h:outputText value="#{data}"/&gt;
      &lt;/p:column&gt;
  &lt;/p:treeTable&gt;
  </code></pre>
  
  <p>This is my manager bean:</p>
  
  <pre><code>@Named("treeTableManager")
  @SessionScoped
  public class TreeTableManager implements Serializable {
  
  private TreeNode treeNode;
  
  private TreeNode[] selectedTreeNode;
  
  //gets and sets...
  
  public TreeTableManager(){
      this.treeNode = new DefaultTreeNode("root", null);
      TreeNode t = new DefaultTreeNode("NodeFather", this.treeNode);
  }
  
  
  public void onNodeUnselect(NodeUnselectEvent event){
      this.treeNode.getChildren().remove(event.getTreeNode());
  }
  </code></pre>
  
  <p>But I got the stack trace below:</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      at java.util.ArrayList.rangeCheck(ArrayList.java:604)
      at java.util.ArrayList.get(ArrayList.java:382)
      at org.primefaces.component.api.UITree.findTreeNode(UITree.java:121)
      at org.primefaces.component.api.UITree.setRowKey(UITree.java:80)
      at org.primefaces.component.api.UITree.visitTree(UITree.java:417)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
      at javax.faces.component.UIForm.visitTree(UIForm.java:344)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
      at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
      at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:297)
      at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
      at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:981)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:391)
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
      at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
      at com.mediaretrievers.controller.login.AuthenticationFilter.doFilter(AuthenticationFilter.java:36)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
      at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>In the page nothing happened. The update didn't work with the treeNode. Despite of the stack trace and the error on the page, I realized that the node has deleted.</p>
  
  <p>I have thought this problem was caused by something in the ajax, then I did this test below.</p>
  
  <pre><code>          &lt;p:commandButton id="hideBotton" widgetVar="buttonObject" 
                                                   update=":form:treeTable" process="@this" 
                                                   actionListener="#{treeTableManager.onNodeUnselect}"/&gt;
  
                                  &lt;p:treeTable id="treeTable" value="#{treeTableManager.treeNode}" var="data" 
                                               selection="#{treeTableManager.selectedTreeNode}"
                                               selectionMode="checkbox"&gt;
  &lt;p:ajax event="unselect" oncomplete="buttonObject.jq.click()" listener="#{treeTableManager.setNodeEventTrigger}" /&gt;
                                      &lt;p:column&gt;
                                          &lt;f:facet name="header"&gt;
                                              teste
                                          &lt;/f:facet&gt;
                                          &lt;h:outputText value="#{data}"/&gt;
                                      &lt;/p:column&gt;
                                  &lt;/p:treeTable&gt;
  </code></pre>
  
  <p>And modify the onNodeUnselect method:</p>
  
  <pre><code>public void onNodeUnselect(){
      //I have done it just to simplify the exemple.
      this.treeNode.getChildren().remove(0);
  }
  </code></pre>
  
  <p>I changed the way of the funcionality just to simulate a test, making the ajax's call executes first and calling the click method of the hideBotton when the ajax complete its calling. So, the hideBotton calls the onNodeUnselect listener method and update the treeNode.</p>
  
  <p>I don't know what's going on, but from what I have seen, is something in ajax. Could someone give me a hint?</p>