我试图创建一个treeTable组件(PrimeFaces 3.5),当它发生的unselect ajax事件(取消复选框),我想删除这个未选中的(Unchecked) treeNode,使用onNodeUnselect侦听器方法:
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完成调用时调用hidebutton的click方法。因此,hidebutton调用onNodeUnselect侦听器方法并更新treeNode。
我不知道发生了什么,但从我所看到的,是ajax的东西。有人能给我点提示吗?
可能和我们遇到的问题一样。在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分支的一个分支(http://blog.primefaces.org/?p=2498)。