Primefaces TreeTable: Deleting node using p:ajax not work

Erick Alves Source

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:

XHTML

<p:treeTable id="treeTable" value="#{treeTableManager.treeNode}" var="data" 
             selection="#{treeTableManager.selectedTreeNode}"
             selectionMode="checkbox">
    <p:ajax event="unselect" update=":form:treeTable" listener="#{treeTableManager.onNodeUnselect}" />
    <p:column>
        <f:facet name="header">
            Title
        </f:facet>
        <h:outputText value="#{data}"/>
    </p:column>
</p:treeTable>

This is my manager bean:

@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());
}

But I got the stack trace below:

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)

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.

I have thought this problem was caused by something in the ajax, then I did this test below.

          <p:commandButton id="hideBotton" widgetVar="buttonObject" 
                                                 update=":form:treeTable" process="@this" 
                                                 actionListener="#{treeTableManager.onNodeUnselect}"/>

                                <p:treeTable id="treeTable" value="#{treeTableManager.treeNode}" var="data" 
                                             selection="#{treeTableManager.selectedTreeNode}"
                                             selectionMode="checkbox">
<p:ajax event="unselect" oncomplete="buttonObject.jq.click()" listener="#{treeTableManager.setNodeEventTrigger}" />
                                    <p:column>
                                        <f:facet name="header">
                                            teste
                                        </f:facet>
                                        <h:outputText value="#{data}"/>
                                    </p:column>
                                </p:treeTable>

And modify the onNodeUnselect method:

public void onNodeUnselect(){
    //I have done it just to simplify the exemple.
    this.treeNode.getChildren().remove(0);
}

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.

I don't know what's going on, but from what I have seen, is something in ajax. Could someone give me a hint?

javajsfprimefaces

Answers

answered 5 years ago fischermatte #1

Maybe the same issue we had. It was fixed in Primefaces 3.4.4, 3.5.2 and the upcoming 4.0. See http://code.google.com/p/primefaces/issues/detail?id=5255. Unfortunately the 3.4.4 and 3.5.2 releases you can only obtain when you are subscribed as PRO or ELITE.If you dont have it you can either wait for 4.0 or merge this fix into an own branch of a 3.5 fork (http://blog.primefaces.org/?p=2498).

comments powered by Disqus