我正在尝试创建一个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>
这是我的经理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());
}
但我得到了下面的堆栈跟踪:
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中的东西。有人能给我一个暗示吗?
答案 0 :(得分: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分叉的自己的分支中{{3 }})。