在数据表中使用 List<CustomObject> 时出现 NumberFormatException
Posted
技术标签:
【中文标题】在数据表中使用 List<CustomObject> 时出现 NumberFormatException【英文标题】:NumberFormatException when using List<CustomObject> in datatable 【发布时间】:2012-06-16 00:16:14 【问题描述】:尝试在数据表中显示列表时遇到 NumberFormatException。我知道发生此异常的一般原因,但无法弄清楚它适用于我的情况。
这是我的冰:数据表显示代码
<ice:dataTable id="transformations" var="transformationList"
value="#ShowStatusBean.transformationStatusList" rows="10"
partialTriggers="refreshButton" autoSubmit="true">
<ice:column>
<ice:outputText value="#transformationList.businessDate" />
</ice:column>
<ice:column>
<ice:outputText value="#transformationList.service" />
</ice:column>
<ice:column>
<ice:outputText value="#transformationList.status" />
</ice:column>
</ice:dataTable>
还有我的支持 bean 代码
public List<TransformationBean> getTransformationStatusList()
transformationStatusList = new ArrayList<TransformationBean>();
transformationStatusList.add(new TransformationBean("2012-01-01", "serviceName", "status1"));
transformationStatusList.add(new TransformationBean("2012-01-02", "serviceName2", "status2"));
return transformationStatusList;
最后是堆栈跟踪
23:59:57 ERROR [f-tuning)'] D2DFaceletViewHandler - Problem in renderResponse: For input string: "businessDate"
java.lang.NumberFormatException: For input string: "businessDate"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:138)
at com.sun.el.parser.AstValue.getValue(AstValue.java:96)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
at javax.faces.component.UIOutput.getValue(UIOutput.java:80)
at com.icesoft.faces.renderkit.dom_html_basic.OutputTextRenderer.encodeEnd(OutputTextRenderer.java:91)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:369)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.component.ext.renderkit.TableRenderer.encodeChildren(TableRenderer.java:896)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:357)
at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.component.util.CustomComponentUtils.renderChild(CustomComponentUtils.java:338)
at com.icesoft.faces.component.panelpopup.PanelPopupRenderer.encodeBegin(PanelPopupRenderer.java:240)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:515)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:355)
at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:357)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:357)
at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.component.util.CustomComponentUtils.renderChild(CustomComponentUtils.java:338)
at com.icesoft.faces.component.paneltabset.PanelTabSetRenderer.writeTabCell(PanelTabSetRenderer.java:983)
at com.icesoft.faces.component.paneltabset.PanelTabSetRenderer.encodeEnd(PanelTabSetRenderer.java:422)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
at javax.faces.component.UIData.encodeEnd(UIData.java:573)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:369)
at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:207)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:357)
at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:357)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:357)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:364)
at com.icesoft.faces.renderkit.dom_html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:490)
at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:495)
at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:495)
at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:495)
at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:495)
at com.icesoft.faces.facelets.D2DFaceletViewHandler.renderResponse(D2DFaceletViewHandler.java:281)
at com.icesoft.faces.application.D2DViewHandler.renderView(D2DViewHandler.java:155)
at com.icesoft.faces.application.ViewHandlerProxy.renderView(ViewHandlerProxy.java:70)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
at com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:51)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:171)
at com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:112)
at com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:65)
at com.icesoft.faces.webapp.http.servlet.BasicAdaptingServlet.service(BasicAdaptingServlet.java:48)
at com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:58)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:55)
at com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:77)
at com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:55)
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:192)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:67)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
还有我的 TransformationBean
public class TransformationBean
private String businessDate;
private String service;
private String status;
// constructor
// getter and setters
我研究了这个问题并找到了很多回应。但看起来我没有犯任何这些错误..所以不确定我错过了什么。 这些是我发现的关于同一问题的其他链接。
Number format exception when returning values from database(JPA)
NumberFormatException for input String
http://jforum.icesoft.org/JForum/posts/list/16645.page
所有这些都提到从 java 代码返回的 List 是一个 List of Object[] 这就是为什么它试图通过将属性视为索引属性来访问数组条目的原因。但是,从我的代码中,很明显我没有返回一个 List of Object[] ,而是一个正确的定义列表
我还在 JUNit 测试用例中测试了 java 代码,并验证了返回类型是一个 TransformationBean 对象列表。
伙计们,我做错了什么?
【问题讨论】:
您能告诉我“TransformationBean”是什么意思吗?并告诉我 TransformationBean 的参数和类型。 TrasformationBean 只是我的 POJO.. 将其添加到上面的原始帖子中 您是否尝试过将列表作为托管 bean 的属性并使用 getter 中的方法填充它? 你100%确定TransformationBean
没有实现List
接口吗?应用程序的行为就像它一样。
【参考方案1】:
我能够解决问题。不知道问题是什么。我刚刚创建了一个新文件,其中包含具有相同信息集的 xhtml 显示代码。我唯一改变的就是将 var 名称更改为 bean 像这样..
<ice:dataTable id="transformations" var="bean"
value="#ShowStatusBean.transformationStatusList" rows="10"
partialTriggers="refreshButton" autoSubmit="true">
<ice:column>
<ice:outputText value="#bean.businessDate" />
</ice:column>
<ice:column>
<ice:outputText value="#bean.service" />
</ice:column>
<ice:column>
<ice:outputText value="#bean.status" />
</ice:column>
</ice:dataTable>`
它开始工作..没有意义..也许应用服务器正在缓存一些不正确的以前版本..但看起来我的代码一直都是正确的..
【讨论】:
以上是关于在数据表中使用 List<CustomObject> 时出现 NumberFormatException的主要内容,如果未能解决你的问题,请参考以下文章
使用 DataGrid 以编程方式收集输入数据并将其存储在 List<> 中
如何在 Android 中使用 Parcelable 读取 List<List<List<Double>>