2

我正在尝试创建一个 treeTable 组件(PrimeFaces 3.5),当它发生取消选择 ajax 事件(取消选中该框)时,我想使用 onNodeUnselect 侦听器方法删除这个未选中(未选中)treeNode:

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>

这是我的经理豆:

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

但我得到了下面的堆栈跟踪:

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)

在页面中没有发生任何事情。更新不适用于 treeNode。尽管存在堆栈跟踪和页面上的错误,但我意识到该节点已被删除。

我一直认为这个问题是由ajax中的某些东西引起的,然后我在下面做了这个测试。

          <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>

并修改 onNodeUnselect 方法:

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

我改变了功能的方式只是为了模拟一个测试,让ajax的调用首先执行,并在ajax完成调用时调用hideBotton的click方法。因此,hideBotton 调用 onNodeUnselect 侦听器方法并更新 treeNode。

我不知道发生了什么,但据我所见,是 ajax 中的东西。有人可以给我一个提示吗?

4

1 回答 1

3

也许我们遇到了同样的问题。它已在 Primefaces 3.4.4、3.5.2 和即将推出的 4.0 中修复。请参阅http://code.google.com/p/primefaces/issues/detail?id=5255。不幸的是,3.4.4 和 3.5.2 版本只有在您订阅为 PRO 或 ELITE 时才能获得。如果您没有它,您可以等待 4.0 或将此修复合并到 3.5 fork 的自己的分支中(http:/ /blog.primefaces.org/?p=2498)。

于 2013-04-12T08:07:54.623 回答