Question

hibernate generated the following query :

Hibernate: 
    insert 
    into
        RegForm
        (description, name, pic) 
    values
        (?, ?, ?)
Hibernate: 
    select
        regform0_.id as id0_,
        regform0_.description as descript2_0_,
        regform0_.name as name0_,
        regform0_.pic as pic0_ 
    from
        RegForm regform0_

in my controller:

    @RequestMapping(value="/profile")
    public String profiles(Model model){
         List<RegForm> regdetails=regservice.findAll();




//       System.out.println(regdetails);
         model.addAttribute("regdetails",regdetails);
        return "profile";
    }

in jsp file:

${regdetails.id}

but it won't work and generating a error message like this.

java.lang.NumberFormatException: For input string: "id"
    java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    java.lang.Integer.parseInt(Integer.java:492)
    java.lang.Integer.parseInt(Integer.java:527)
    javax.el.ListELResolver.coerce(ListELResolver.java:163)
    javax.el.ListELResolver.getValue(ListELResolver.java:51)
    org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
    org.apache.el.parser.AstValue.getValue(AstValue.java:182)
    org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967)
    org.apache.jsp.WEB_002dINF.jsp.profile_jsp._jspService(profile_jsp.java:75)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja

How can i tackle this situation ? i am using spring mvc + hibernate . when i request to profile.jsp it won't work i am new to hibernate and spring . it would be very nice if some one explain whats goes on behind the seen .

Was it helpful?

Solution

You have a RegForm list that you are passing as modelattribute in the jsp. So if you wan to see each of the id in the list, you need to iterate it as:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <html>
      <head>
         ...
     </head>
        <title>Jsp Title</title>    
        <body onload="javascript:loadOnValues();">   
        <form:form method="post" action="someAction" modelAttribute="regdetails">
           <c:forEach var="regForm" items="${regdetails}">
            <tr>
                <td>
                   Id: ${regForm.id}
                </td>
            </tr>
           </c:forEach>
        </form:form>
      </body>
    </html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top