web-dev-qa-db-ja.com

入力文字列のNumberFormatException

JSFバッキングBeanには次のメソッドがあります。

public List<Rent> getTopMemebers(){
    return rentDAO.findByMonthAndYear(MonthReport, YearReport);
}

私はこれをデータテーブルに表示しています:

<p:dataTable value="#{rentController.topMemebers}" var="item">
    <p:column>
        <h:outputText value="#{item.rentid}"/>
    </p:column>
    ...
</p:dataTable>

しかし、次の例外がありました。

SEVERE: Error Rendering View[/admin/index.xhtml]
Java.lang.NumberFormatException: For input string: "rentid"
        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 javax.el.ArrayELResolver.toInteger(ArrayELResolver.Java:375)
        at javax.el.ArrayELResolver.getValue(ArrayELResolver.Java:195)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.Java:175)
        at com.Sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.Java:72)
        at com.Sun.el.parser.AstValue.getValue(AstValue.Java:116)
        at com.Sun.el.parser.AstValue.getValue(AstValue.Java:163)
        at com.Sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.Java:219)
        at com.Sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.Java:102)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.Java:190)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.Java:178)
        at javax.faces.component.UIOutput.getValue(UIOutput.Java:168)
        at com.Sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.Java:205)
        at com.Sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.Java:338)
        at com.Sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.Java:164)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.Java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1620)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1616)
        at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.Java:489)
        at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.Java:416)
        at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.Java:164)
        at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.Java:80)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.Java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1620)
        at javax.faces.render.Renderer.encodeChildren(Renderer.Java:168)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.Java:848)
        at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.Java:55)
        at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.Java:43)
        at org.primefaces.component.dialog.DialogRenderer.encodeMarkup(DialogRenderer.Java:118)
        at org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.Java:48)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.Java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1620)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1616)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1616)
        at com.Sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.Java:380)
        at com.Sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.Java:126)
        at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.Java:157)
        at com.Sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.Java:127)
        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:313)
        at org.Apache.catalina.core.StandardWrapper.service(StandardWrapper.Java:1523)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:343)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.Java:113)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:256)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at org.Apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.Java:820)
        at org.Apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.Java:684)
        at org.Apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.Java:517)
        at org.Apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.Java:488)
        at org.Apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.Java:379)
        at org.Apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.Java:336)
        at org.Apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.Java:314)
        at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.Java:104)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:256)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at com.mcgraw.controller.UserLoginFilter.doFilter(UserLoginFilter.Java:59)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:256)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:277)
        at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:188)
        at org.Apache.catalina.core.StandardPipeline.invoke(StandardPipeline.Java:641)
        at com.Sun.enterprise.web.WebPipeline.invoke(WebPipeline.Java:97)
        at com.Sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.Java:85)
        at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:185)
        at org.Apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.Java:325)
        at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:226)
        at com.Sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.Java:165)
        at com.Sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.Java:791)
        at com.Sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.Java:693)
        at com.Sun.grizzly.http.ProcessorTask.process(ProcessorTask.Java:954)
        at com.Sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.Java:170)
        at com.Sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.Java:135)
        at com.Sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.Java:102)
        at com.Sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.Java:88)
        at com.Sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.Java:76)
        at com.Sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.Java:53)
        at com.Sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.Java:57)
        at com.Sun.grizzly.ContextTask.run(ContextTask.Java:69)
        at com.Sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.Java:330)
        at com.Sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.Java:309)
        at Java.lang.Thread.run(Thread.Java:619)

WARNING: ApplicationDispatcher[/mcGrawLibPro-war] PWC1231: Servlet.service() for servlet Faces Servlet threw exception
Java.lang.NumberFormatException: For input string: "rentid"
        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 javax.el.ArrayELResolver.toInteger(ArrayELResolver.Java:375)
        at javax.el.ArrayELResolver.getValue(ArrayELResolver.Java:195)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.Java:175)
        at com.Sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.Java:72)
        at com.Sun.el.parser.AstValue.getValue(AstValue.Java:116)
        at com.Sun.el.parser.AstValue.getValue(AstValue.Java:163)
        at com.Sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.Java:219)
        at com.Sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.Java:102)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.Java:190)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.Java:178)
        at javax.faces.component.UIOutput.getValue(UIOutput.Java:168)
        at com.Sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.Java:205)
        at com.Sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.Java:338)
        at com.Sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.Java:164)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.Java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1620)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1616)
        at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.Java:489)
        at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.Java:416)
        at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.Java:164)
        at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.Java:80)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.Java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1620)
        at javax.faces.render.Renderer.encodeChildren(Renderer.Java:168)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.Java:848)
        at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.Java:55)
        at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.Java:43)
        at org.primefaces.component.dialog.DialogRenderer.encodeMarkup(DialogRenderer.Java:118)
        at org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.Java:48)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.Java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1620)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1616)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.Java:1616)
        at com.Sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.Java:380)
        at com.Sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.Java:126)
        at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.Java:157)
        at com.Sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.Java:127)
        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:313)
        at org.Apache.catalina.core.StandardWrapper.service(StandardWrapper.Java:1523)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:343)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.Java:113)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:256)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at org.Apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.Java:820)
        at org.Apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.Java:684)
        at org.Apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.Java:517)
        at org.Apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.Java:488)
        at org.Apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.Java:379)
        at org.Apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.Java:336)
        at org.Apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.Java:314)
        at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.Java:104)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:256)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at com.mcgraw.controller.UserLoginFilter.doFilter(UserLoginFilter.Java:59)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:256)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:215)
        at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:277)
        at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:188)
        at org.Apache.catalina.core.StandardPipeline.invoke(StandardPipeline.Java:641)
        at com.Sun.enterprise.web.WebPipeline.invoke(WebPipeline.Java:97)
        at com.Sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.Java:85)
        at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:185)
        at org.Apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.Java:325)
        at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:226)
        at com.Sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.Java:165)
        at com.Sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.Java:791)
        at com.Sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.Java:693)
        at com.Sun.grizzly.http.ProcessorTask.process(ProcessorTask.Java:954)
        at com.Sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.Java:170)
        at com.Sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.Java:135)
        at com.Sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.Java:102)
        at com.Sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.Java:88)
        at com.Sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.Java:76)
        at com.Sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.Java:53)
        at com.Sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.Java:57)
        at com.Sun.grizzly.ContextTask.run(ContextTask.Java:69)
        at com.Sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.Java:330)
        at com.Sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.Java:309)
        at Java.lang.Thread.run(Thread.Java:619)

それはどのように引き起こされ、どうすれば修正できますか?\

11
MYE

そう、

_<h:outputText value="#{item.rentid}" />
_

これを引き起こしています:

_Java.lang.NumberFormatException: For input string: "rentid"
    ...
    at javax.el.ArrayELResolver.getValue(ArrayELResolver.Java:195)
    ...
    at javax.faces.component.UIOutput.getValue(UIOutput.Java:168)
_

実行していると思われるコードを実行していますか?スタックトレースにArrayELResolverが含まれていることは、_#{item}_が実際には _Object[]_のような配列であることを示しています。配列値は、_#{item[0]}_のような整数インデックスによってのみ取得できますが、この例外の原因となった_#{item.rentid}_として文字列rentidを使用して配列値にアクセスしています。

RentController#getTopMembers()が_List<Rent>_ではなく_List<Object[]>_を返すこと、およびRentControllerの正しいバージョンが_#{rentController}_マネージドBeanとして宣言されていることを確認してください。

25
BalusC