title: Displaying Object List From Class In Jsp
body: <p>I am using Spring MVC and i implemented <strong>ResultSetExtractor</strong> since one of my classes had a complex list object. I did the mappings and then made the select from the database. I am having problems displaying the data from the list items in the <strong>ResultSetExtractor</strong>. I am hoping that i did the mapping correctly. The other attributes have data. The issue is displaying the values from the Listvictims and Listcriminals in the jsp.</p>
  
  <p>Under is the code:</p>
  
  <p><strong>Jsp</strong></p>
  
  <p>I am getting data in the crimeRecNo and the crimeDetails however non in the victim.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I updated the code however i am not getting any values back in the victims list nothing is printed on the jsp. The other elements are getting data. I am not sure if the ResultSetExtractor was written up properly for the list items. </p>
  
  <pre><code>&lt;form:form id="crimeList" name ="crimeList"&gt;
      &lt;div id ="content"&gt;
          &lt;c:forEach items="${crimes}" var="crime"&gt;
              &lt;div id="table"&gt;        
  
                  &lt;label&gt;${crime.crimeRecNo}&lt;/label&gt;
                  &lt;label&gt;${crime.crimeDetails}&lt;/label&gt;
  
                  &lt;c:forEach items="${crime.victims}" var="victim"&gt;
                      &lt;label&gt;${victim.fName}&lt;/label&gt;     
                  &lt;/c:forEach&gt;
  
              &lt;/div&gt;
          &lt;/c:forEach&gt;
      &lt;/div&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p><strong>ResultSetExtractor Mappings</strong></p>
  
  <p>Please correct me if i did the mapping incorrectly</p>
  
  <pre><code>private static final class CrimeMapper implements ResultSetExtractor&lt;List&lt;Crime&gt;&gt;{
  
      public List&lt;Crime&gt; extractData(ResultSet rs) throws SQLException, DataAccessException {
  
          Map&lt;Integer, Crime&gt; map = new HashMap&lt;Integer, Crime&gt;();
          Crime crime = null;
  
          while (rs.next()){
  
              int crimeRecNo = rs.getInt("crimeRecNo");
              crime = map.get(crimeRecNo);
              if (crime == null){
                  crime = new Crime();
                  crime.setCrimeRecNo(crimeRecNo);
                  crime.setCrimeDate(rs.getString("crimeDate"));
                  crime.setCrimeDetails(rs.getString("crimeDetails"));
                  crime.setCrimeStreetLn1(rs.getString("crimeStreetLn1"));
                  crime.setCrimeStreetLn2(rs.getString("crimeStreetLn2"));
                  crime.setCrimeLatLocation(rs.getBigDecimal("crimeLatLocation"));
                  crime.setCrimeLongLocation(rs.getBigDecimal("crimeLongLocation"));
                  crime.setCrimeTime(rs.getString("crimeTime"));
                  crime.setInvestigatingOfficerId(rs.getString("investigatingOfficerId"));
                  crime.setCrimeLevelId(rs.getInt("crimeLevelId"));
                  crime.setOffenceCatId(rs.getInt("offenceCatId"));
                  crime.setOffenceTypeId(rs.getInt("offenceTypeId"));
                  crime.setStatusId(rs.getInt("statusId"));
                  crime.setRecordedById(rs.getString("recordedById"));
                  crime.setVictims(new ArrayList&lt;Citizens&gt;());
                  crime.setCriminals(new ArrayList&lt;Citizens&gt;());
                  map.put(crimeRecNo, crime);
              }
  
              Integer socialSecurityNumber = rs.getInt("socialSecurityNumber");
              Integer citizenTypeId = rs.getInt("citizenTypeId");
              if(socialSecurityNumber &gt; 0 &amp; citizenTypeId == 3){
                  Citizens victims = new Citizens();
                  victims.setAddLn1(rs.getString("addLn1"));
                  victims.setAddLn2(rs.getString("addLn2"));
                  victims.setAddLn3(rs.getString("addLn3"));
                  victims.setCitizenTypeId(rs.getInt("citizenTypeId"));
                  victims.setCountryId(rs.getInt("countryId"));
                  victims.setEthnicityId(rs.getInt("ethnicityId"));
                  victims.setfName(rs.getString("fName"));
                  victims.setGenderId(rs.getString("genderId"));
                  victims.setHairColorId(rs.getString("hairColorId"));
                  victims.setHeight(rs.getDouble("height"));
                  victims.setlName(rs.getString("lName"));
                  victims.setMaritalStatusId(rs.getInt("maritalStatusId"));
                  victims.setNoticeableFeatures(rs.getString("noticableFeatures"));
                  victims.setOccupationId(rs.getInt("occupationId"));
                  victims.setoName(rs.getString("oName"));
                  victims.setPhoneNo(rs.getString("phoneNo"));
                  victims.setPhoto(rs.getString("photo"));
                  victims.setSkinColorId(rs.getString("skinColorId"));
                  victims.setSocialSecurityNumber(rs.getInt("socialSecurityNumber"));
                  victims.setWeight(rs.getDouble("weight"));
                  victims.setEyeColorId(rs.getString("eyeColorId"));
                  victims.setDob(rs.getDate("dob"));
                  victims.setName(rs.getString("fName") +" "+ rs.getString("lName"));
  
                  crime.getVictims().add(victims);
              } else if(socialSecurityNumber &gt; 0 &amp; citizenTypeId == 2){
                  Citizens criminal = new Citizens();
                  criminal.setAddLn1(rs.getString("addLn1"));
                  criminal.setAddLn2(rs.getString("addLn2"));
                  criminal.setAddLn3(rs.getString("addLn3"));
                  criminal.setCitizenTypeId(rs.getInt("citizenTypeId"));
                  criminal.setCountryId(rs.getInt("countryId"));
                  criminal.setEthnicityId(rs.getInt("ethnicityId"));
                  criminal.setfName(rs.getString("fName"));
                  criminal.setGenderId(rs.getString("genderId"));
                  criminal.setHairColorId(rs.getString("hairColorId"));
                  criminal.setHeight(rs.getDouble("height"));
                  criminal.setlName(rs.getString("lName"));
                  criminal.setMaritalStatusId(rs.getInt("maritalStatusId"));
                  criminal.setNoticeableFeatures(rs.getString("noticableFeatures"));
                  criminal.setOccupationId(rs.getInt("occupationId"));
                  criminal.setoName(rs.getString("oName"));
                  criminal.setPhoneNo(rs.getString("phoneNo"));
                  criminal.setPhoto(rs.getString("photo"));
                  criminal.setSkinColorId(rs.getString("skinColorId"));
                  criminal.setSocialSecurityNumber(rs.getInt("socialSecurityNumber"));
                  criminal.setWeight(rs.getDouble("weight"));
                  criminal.setEyeColorId(rs.getString("eyeColorId"));
                  criminal.setDob(rs.getDate("dob"));
                  criminal.setName(rs.getString("fName") +" "+ rs.getString("lName"));
                  crime.getCriminals().add(criminal);                 
              }               
          }           
          return new ArrayList&lt;Crime&gt;(map.values());
      }       
  }   
  </code></pre>
  
  <p><strong>Crime.java</strong></p>
  
  <pre><code>public class Crime implements Serializable{
  
      private int crimeRecNo;
      private String crimeDetails;
      private BigDecimal crimeLatLocation;
      private BigDecimal crimeLongLocation;
      private String crimeStreetLn1;
      private String crimeStreetLn2;
      private String crimeDate;
      private String crimeTime;
      private List&lt;Citizens&gt; victims;
      private List&lt;Citizens&gt; criminals;   
      private String recordedById;
      private int statusId;
      private int offenceCatId;
      private int offenceTypeId;
      private int crimeLevelId;
      private String investigatingOfficerId;
  </code></pre>
  
  <p>..........</p>
  
  <p><strong>Citizens.java</strong></p>
  
  <pre><code>public class Citizens implements Serializable{
  
      private int socialSecurityNumber;
      private String fName;
      private String lName;
      private String oName;
      private String photo;
      private int countryId;
      private String addLn1;
      private String addLn2;
      private String addLn3;
      private String genderId;
      private int ethnicityId;
      private String skinColorId;
      private String hairColorId;
      private int occupationId;
      private String phoneNo;
      private int maritalStatusId;
      private String noticeableFeatures;
      private double weight;
      private double height;
      private int citizenTypeId;
      private String eyeColorId;
      private Date dob;
      private String name;
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/crimeList.jsp at line 62
  
  59:        &lt;label&gt;${crime.crimeRecNo}&lt;/label&gt;
  60:        &lt;label&gt;${crime.crimeDetails}&lt;/label&gt;
  61:        
  62:        &lt;c:forEach items="${crimes.getVictims}" var="victim"&gt;
  63:        &lt;label&gt;${victim.getName}&lt;/label&gt;
  64:        
  65:        &lt;/c:forEach&gt;
  
  
  Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  
  root cause
  
  java.lang.NumberFormatException: For input string: "getVictims"
      java.lang.NumberFormatException.forInputString(Unknown Source)
      java.lang.Integer.parseInt(Unknown Source)
      java.lang.Integer.parseInt(Unknown Source)
      javax.el.ListELResolver.coerce(ListELResolver.java:173)
      javax.el.ListELResolver.getValue(ListELResolver.java:52)
      org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
      org.apache.el.parser.AstValue.getValue(AstValue.java:183)
      org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
      org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
      org.apache.jsp.WEB_002dINF.jsp.crimeList_jsp._jspx_meth_c_005fforEach_005f1(crimeList_jsp.java:249)
      org.apache.jsp.WEB_002dINF.jsp.crimeList_jsp._jspx_meth_c_005fforEach_005f0(crimeList_jsp.java:216)
      org.apache.jsp.WEB_002dINF.jsp.crimeList_jsp._jspx_meth_form_005fform_005f0(crimeList_jsp.java:164)
      org.apache.jsp.WEB_002dINF.jsp.crimeList_jsp._jspService(crimeList_jsp.java:127)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  </code></pre>