NumberFormatException for input String

MYE picture MYE · Dec 10, 2010 · Viewed 38.1k times · Source

I have the following method in a JSF backing bean:

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

I am displaying this in a datatable:

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

But I got the following exception:

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)

How is it caused and how can I fix it?\

Answer

BalusC picture BalusC · Dec 11, 2010

So,

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

is causing this:

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

Are you running the code you think you're running? The involvement of ArrayELResolver in the stacktrace indicates that #{item} is actually an array like Object[]. Array values can only be obtained by an integer index like #{item[0]}, but you're accessing it with a string rentid as #{item.rentid} which caused this exception.

Ensure that RentController#getTopMembers() returns a List<Rent>, not List<Object[]> and that the correct version of RentController is been declared as #{rentController} managed bean.