title: bake form in spring mvc for edit
body: <p>total beginner to spring mvc.
  I need to prepopulate edit form in springmvc frame-work.</p>
  
  <p>contact_edit.jsp</p>
  
  <pre><code>&lt;form:form method="post" action="edit/1" commandName="contact"&gt;
  &lt;% Contact contact = (Contact)request.getAttribute("contact");  %&gt;
      &lt;table&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="firstname"&gt;
                      &lt;spring:message code="label.firstname" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="firstname" value="&lt;%=contact.getFirstname() %&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="lastname"&gt;
                      &lt;spring:message code="label.lastname" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="lastname" value="&lt;%=contact.getLastname() %&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="email"&gt;
                      &lt;spring:message code="label.email" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="email" value="&lt;%=contact.getEmail()%&gt;" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="telephone"&gt;
                      &lt;spring:message code="label.telephone" /&gt;
                  &lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="telephone" value="&lt;%=contact.getTelephone()%&gt;"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td colspan="2"&gt;&lt;input type="submit"
                  value="&lt;spring:message code="label.addcontact"/&gt;" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>controller code to get this page:</p>
  
  <pre><code>@RequestMapping(value = "/edit/{contactId}", method = RequestMethod.GET)
  public ModelAndView edit(@PathVariable("contactId") Integer contactId,
          HttpServletRequest request) {
      System.out.println("I was here");
      Contact contact = contactService.getContact(contactId);
      request.setAttribute("contact", contact);
      Map&lt;String, Object&gt; model = new HashedMap();
      model.put("contact", contact);
  
      return new ModelAndView("contact_edit", model);
  }
  </code></pre>
  
  <p>My exception:</p>
  
  <pre><code>org.springframework.beans.InvalidPropertyException: Invalid property 'firstname' of bean class [net.viralpatel.contact.form.Contact_$$_javassist_0]: Getter for property 'firstname' threw exception; nested exception is java.lang.reflect.InvocationTargetException
  org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:845)
  org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:721)
  org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
  org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:219)
  org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:120)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
  org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
  org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
  org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
  org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
  org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
  org.apache.jsp.WEB_002dINF.jsp.contact_005fedit_jsp._jspx_meth_form_005flabel_005f0(contact_005fedit_jsp.java:320)
  org.apache.jsp.WEB_002dINF.jsp.contact_005fedit_jsp._jspService(contact_005fedit_jsp.java:147)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  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.doGet(FrameworkServlet.java:778)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  
  root cause
  
    java.lang.reflect.InvocationTargetException
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:601)
  org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:761)
  org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:721)
  org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
  org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:219)
  org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:120)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
  org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
  org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
  org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
  org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
  org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
  org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
  org.apache.jsp.WEB_002dINF.jsp.contact_005fedit_jsp._jspx_meth_form_005flabel_005f0(contact_005fedit_jsp.java:320)
  org.apache.jsp.WEB_002dINF.jsp.contact_005fedit_jsp._jspService(contact_005fedit_jsp.java:147)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  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.doGet(FrameworkServlet.java:778)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  </code></pre>
  
  <p>My Contact Class:</p>
  
  <pre><code>@Entity
  @Table(name="CONTACTS")
  public class Contact {
  
  @Id
  @Column(name="ID")
  @GeneratedValue
  private Integer id;
  
  @Column(name="FIRSTNAME")
  private String firstname;
  
  @Column(name="LASTNAME")
  private String lastname;
  
  @Column(name="EMAIL")
  private String email;
  
  @Column(name="TELEPHONE")
  private String telephone;
  
  
  public String getEmail() {
      return email;
  }
  public String getTelephone() {
      return telephone;
  }
  public void setEmail(String email) {
      this.email = email;
  }
  public void setTelephone(String telephone) {
      this.telephone = telephone;
  }
  public String getFirstname() {
      return firstname;
  }
  public String getLastname() {
      return lastname;
  }
  public void setFirstname(String firstname) {
      this.firstname = firstname;
  }
  public void setLastname(String lastname) {
      this.lastname = lastname;
  }
  public Integer getId() {
      return id;
  }
  public void setId(Integer id) {
      this.id = id;
  }
  
  }
  </code></pre>
  
  <p>My Contact class contains all getters and setters method , even my create form is working fine. Can't figure out what is creating problem where . I have already inserted contact object in request as well as in ModelAndView class. !!!??!!</p>