NumberFormatException in a jsp with a list

12,619

This means that ${requiredRequirement} is actually an instance of List. In EL, a List can only be accessed by an integer index. This can have 2 causes:

  1. Your Requirement class actually implements List or extends one of its subclasses.
  2. The ${level} or ${level.requirements} actually doesn't refer the code you think it does.

As quick debug, try printing them plain to check if their toString() method returns what you would expect:

<p>Level: ${level}</p>
<p>Level requirements: ${level.requirements}</p>

and inside the loop

<p>Required requirement: ${requiredRequirement}</p>
Share:
12,619

Related videos on Youtube

Collin O'Connor
Author by

Collin O'Connor

Updated on June 04, 2022

Comments

  • Collin O'Connor
    Collin O'Connor almost 2 years

    This question is another problem im having with my application which is described here. My model (a level) has a list of requirements which contains two strings, an id and name. The model looks like this:

    public class Level {
    private String name;
    private int id;
    private int points
    private List<Requirement> requirements;
        ....
    }
    
    public class Requirement{
        private String name;
        private String id;
        ....
    }
    

    and the jsp looks like this:

    <div id="allRequirements">
        <c:forEach var="requirement" items="${RequirementList}">
             <div class="requirements">
                 <input type="hidden" value="${requirement.id}" name="id"/>
                 <h2><c:out value="${requirement.name}"/></h2>
             </div>
        </c:foreach>
    </div>
    
    <div id="requiredRequirements">
        <c:forEach var="requiredRequirement" items="${level.requirements}">
             <div class="requirements">
                 <input type="hidden" value="${requiredRequirement.id}" name="id"/>
                 <h2><c:out value="${requiredRequirement.name}"/></h2>
             </div>
        </c:foreach>
    </div>
    

    The jsp page renders fine and works like a charm until I added the requiredRequirements loop in which the site throws a java.lang.NumberFormatException: For input string: "id" because it tries to parse the string as an int.

    Does anyone have any idea why the first loop works and the second loop does not work?

    Edit: Stack trace

    java.lang.NumberFormatException: For input string: "id"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:447)
    at java.lang.Integer.parseInt(Integer.java:497)
    at javax.el.ListELResolver.coerce(ListELResolver.java:174)
    at javax.el.ListELResolver.getValue(ListELResolver.java:52)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:985)
    at org.apache.jsp.WEB_002dINF.jsp.createOrEdit_005fLevelBody_jsp._jspx_meth_c_005fout_005f0(createOrEdit_005fLevelBody_jsp.java:648)
    at org.apache.jsp.WEB_002dINF.jsp.createOrEdit_005fLevelBody_jsp._jspx_meth_c_005fforEach_005f1(createOrEdit_005fLevelBody_jsp.java:611)
    at org.apache.jsp.WEB_002dINF.jsp.createOrEdit_005fLevelBody_jsp._jspService(createOrEdit_005fLevelBody_jsp.java:207)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:927)
    at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
    at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
    at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
    at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
    at org.apache.tiles.renderer.impl.UntypedAttributeRenderer.write(UntypedAttributeRenderer.java:61)
    at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:659)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:337)
    at org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:234)
    at org.apache.tiles.jsp.taglib.InsertAttributeTag.render(InsertAttributeTag.java:211)
    at org.apache.tiles.jsp.taglib.RenderTag.doEndTag(RenderTag.java:220)
    at org.apache.jsp.WEB_002dINF.jsp.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f3(layout_jsp.java:411)
    at org.apache.jsp.WEB_002dINF.jsp.layout_jsp._jspService(layout_jsp.java:196)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:927)
    at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
    at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
    at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
    at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
    at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
    at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:659)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:678)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:633)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:322)
    at org.apache.tiles.jsp.taglib.InsertDefinitionTag.renderContext(InsertDefinitionTag.java:66)
    at org.apache.tiles.jsp.taglib.InsertTemplateTag.render(InsertTemplateTag.java:81)
    at org.apache.tiles.jsp.taglib.RenderTag.doEndTag(RenderTag.java:220)
    at org.apache.jsp.WEB_002dINF.jsp.createOrEdit_005fLevel_jsp._jspx_meth_tiles_005finsertDefinition_005f0(createOrEdit_005fLevel_jsp.java:87)
    at org.apache.jsp.WEB_002dINF.jsp.createOrEdit_005fLevel_jsp._jspService(createOrEdit_005fLevel_jsp.java:60)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:306)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:323)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1719)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
    

    Thanks

  • Collin O'Connor
    Collin O'Connor over 12 years
    All the debug code printed out the correct stuff. And my requirement doesn't implement anything.
  • BalusC
    BalusC over 12 years
    Well, it's time to show the stacktrace. Edit your question to include it.
  • BalusC
    BalusC over 12 years
    A ListELResolver is been involved. The ${requiredRequirement} is at that point definitely an instance of List. Sorry, I can't be more helpful than telling you that you are likely not running the code you think you're running. The possible involvement of some custom/3rd-party EL resolver which is doing its job incorrectly has been excluded based on the stack trace.
  • Collin O'Connor
    Collin O'Connor over 12 years
    Even when i do ${level.requirements[status.index]} i get the correct toString in my loop but once i add .id to the end, things get weird. Makes no sense that i have an object showing up correctly but once I try to get the field from it, the ListResolver gets involved. I will keep looking into it
  • BalusC
    BalusC over 12 years
    Try renaming the variable name. E.g. var="reqdRequirement". If that fixes the problem, then there's a clash somewhere in the EL scope with an existing object with exactly that attribute name.
  • BalusC
    BalusC over 12 years
    Curious. What JARs do you all have in /WEB-INF/lib? What Tomcat version are you using? What Servlet version is your web.xml declared to?
  • Collin O'Connor
    Collin O'Connor over 12 years
    I'm using tomcat version 7 along with maven (no lib folder) and the servlet version is 2.5 I believe.
  • BalusC
    BalusC over 12 years
    Okay, let's ask it differently: what JARs do Maven put in /WEB-INF/lib of the WAR build? Please recheck the servlet API version.
  • BalusC
    BalusC over 12 years
    That was not really helpful... I'd expect to see a list of JARs in /WEB-INF/lib of the WAR (just go to Tomcat's webapps folder and expand the WAR or check the expanded WAR structure). But anyway, you've both JSTL 1.1 and 1.2 impls in your Maven tree. This would only conflict. Get rid of "standard-1.1.2.jar" (which is the JSTL 1.1 impl).
  • Collin O'Connor
    Collin O'Connor over 12 years
    apparently my collectioneditor is doing some crazy stuff. The requiredRequirement is actually a list at runtime.
  • null
    null about 10 years
    Thanks, this answer just helped me, much appreciated :)