2

我目前正在使用 Primefaces 和树表。除了一种情况,我的树表运行良好。让我举一个小例子来解释这个问题:

树表是这样的:

  • 项目1.1
    • 项目2.1
  • 项目1.2
  • 项目1.3

一开始,树倒塌了。树表定义如下:

<p:treeTable id="treetable" value="#{bean.root}" var="node" selectionMode="single" selection="#{bean.selectedNode}">  

我有那些ajax调用:

<p:ajax event="select" listener="#{bean.onSelect}" />

总的来说,一切都运行良好。无论节点的级别如何,都会更新所选节点。问题在于这种情况:

(全部崩溃)

  1. 扩展 Item1.1
  2. 选择项目2.1
  3. 折叠 Item1.1
  4. 选择项目1.2

在这里我得到了例外:

INFO: java.lang.NumberFormatException: For input string: "0,1"
java.lang.NumberFormatException: For input string: "0,1"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at org.primefaces.component.api.UITree.findTreeNode(UITree.java:120)
    at org.primefaces.component.api.UITree.findTreeNode(UITree.java:129)
    at org.primefaces.component.api.UITree.setRowKey(UITree.java:80)
    at org.primefaces.component.treetable.TreeTableRenderer.decodeSelection(TreeTableRenderer.java:57)
    at org.primefaces.component.treetable.TreeTableRenderer.decode(TreeTableRenderer.java:40)
    at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
    at org.primefaces.component.api.UITree.processDecodes(UITree.java:180)
    at org.primefaces.component.treetable.TreeTable.processDecodes(TreeTable.java:325)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:506)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at org.primefaces.component.api.UITree.visitTree(UITree.java:402)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
4

1 回答 1

0

This is PrimeFaces bug in treetable.js, there is issue.

The problem is because unselectAllNodes() function in treetable.js does not clear selection array variable but it should be empty after exit from this function:

unselectAllNodes: function() {
    var selectedNodes = this.tbody.children('tr.ui-state-highlight');

    for(var i = 0; i < selectedNodes.length; i++) {
        this.unselectNode(selectedNodes.eq(i), true);
    }
}

When parent row with previous selected row is expanded this bug not occur, because all visible selected rows (search by ui-state-highlight attribute) unselects with removing from selection array variable. But when parent row is collapsed, tbody.children*('tr.ui-state-highlight')* return empty list, and selection array variable have previous value plus new selectable value separated by comma.

Good news that from PrimeFaces 4.0 release this bug was fixed. because this commit have been inluded to release. One small difference: selection array variable have been renamed to selections by other commits.

unselectAllNodes: function() {
    var selectedNodes = this.tbody.children('tr.ui-state-highlight');
    for(var i = 0; i < selectedNodes.length; i++) {
        this.unselectNode(selectedNodes.eq(i), true);
    }

    this.selections = [];
    this.writeSelections();
}
于 2013-09-09T11:08:56.810 回答