【问题标题】:NumberFormatException PrimeFaces TreeTableNumberFormatException PrimeFaces TreeTable
【发布时间】:2013-07-03 11:32:12
【问题描述】:

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

树表是这样的:

  • 项目1.1
    • Item2.1
  • Item1.2
  • Item1.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)

【问题讨论】:

  • #{bean.selectedNode}的类型是什么?
  • 类型是TreeNode。

标签: primefaces collapse treetable


【解决方案1】:

这是 treetable.js 中的 PrimeFaces 错误,there is issue

问题是因为 treetable.js 中的 unselectAllNodes() 函数没有清除 selection 数组变量,但退出后它应该为空这个函数:

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

当展开带有前一个选定行的父行时,不会发生此错误,因为所有可见的选定行(按 ui-state-highlight 属性搜索)都会取消选择并从 selection中删除> 数组变量。但是当父行被折叠时, tbody.children*('tr.ui-state-highlight')* 返回空列表,并且 selection 数组变量具有以前的值加上以逗号分隔的新可选值。

好消息,PrimeFaces 4.0 版本已修复此错误。因为this commit 已被包含在发布中。一个小区别:selection 数组变量已被其他提交重命名为 selections

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-02-02
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多