title: SPRING MVC: Form Backed Bean Properties not declared as form fields in jsp are set to null
body: <p>I was learning spring mvc. I developed a screen where on login the personal data of a user will show up.On the same screen there will be update button to update the personal data.</p>
  
  <p>My problem is that in the personaldata.jsp , the user properties like username, password which are not mentioned as form fields are set to null after form submit.</p>
  
  <p>Below is my personaldata.jsp</p>
  
  <pre><code>  &lt;form:form name="customerForm" id="customerForm" commandName="customerForm" method="post" &gt;
              &lt;form:hidden path="userName" id="userName"/&gt;
               &lt;form:hidden path="emailAddress" id="emailAddress"/&gt;
               &lt;form:hidden path="password" id="password"/&gt;
              &lt;div class="faq_rightin"&gt;
                  &lt;div class="faq_icon"&gt;&lt;img src='&lt;c:url value="/images/icon19.png" /&gt;' alt=""&gt;&lt;/div&gt;
                  &lt;div class="faq_ohc2"&gt;
                      &lt;h1&gt;&lt;spring:message code="myaccount.label.personaldata" text="Personal Data"&gt;&lt;/spring:message&gt;&lt;/h1&gt;
                      &lt;span class="common ul-font-style m_top "&gt;Welcome ${customerForm.firstName} ${customer.lastName}&lt;/span&gt;
                      &lt;span class="red"&gt;&lt;spring:message code="myaccount.label.personalinfodesc" text="You may here enter your personal Information, enabling you to use those when you make your next booking. Doing so, your user experience is better, quicker."&gt;&lt;/spring:message&gt;&lt;/span&gt;
                      &lt;div class="m_top pd-form-box"&gt;
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;span class="pd-name-title mrg-rgt10"&gt;
                                      &lt;select class="select-pd-name1" id="delivery_method" &gt;
                                          &lt;option class="select-pd-name1" value="0"&gt;Mr&lt;/option&gt;
                                          &lt;option value="1"&gt;Mrs&lt;/option&gt;
                                          &lt;option value="2"&gt;Miss&lt;/option&gt;
                                      &lt;/select&gt;
                                  &lt;/span&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.firstname" text="First Name" var="firstname" /&gt;
                                      &lt;form:input path="firstName" id="firstName" cssClass="pd-form-txt-common pd-txt1 float-left shadow"  placeholder="${firstname}*" /&gt;
                                  &lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;spring:message code="myaccount.label.familyname" text="Family Name" var="lastname"&gt;&lt;/spring:message&gt;
                                  &lt;form:input path="lastName" id="lastName" cssClass="pd-form-txt-common pd-txt2 float-left shadow"  placeholder="${lastname}*" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;div class="comm_md float-left"&gt;
                                      &lt;spring:message code="myaccount.label.emailaddress" text="Email-Address"&gt;&lt;/spring:message&gt;* : ${customerForm.emailAddress}
                                  &lt;/div&gt;
                                  &lt;a href="#" class="comm_md blue_txt bold float-left"&gt;&lt;spring:message code="myaccount.label.changeyouremailaddress" text="Change your Email Address"&gt;&lt;/spring:message&gt; &amp;gt;&lt;/a&gt;                                
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;div class="comm_md float-left"&gt;
                                      &lt;spring:message code="myaccount.label.birthday" text="Birthday"&gt;&lt;/spring:message&gt;*
                                  &lt;/div&gt;
                                  &lt;div class="comm_md float-left"&gt;
                                      &lt;!--&lt;form method="post" action=""&gt;  
                                          &lt;div class="select_md3 float-left"&gt;
                                              &lt;form:select path="day" id="" cssClass="select2"&gt;
                                                  &lt;form:option value="1"&gt;1&lt;/form:option&gt;
                                                  &lt;form:option value="2"&gt;2&lt;/form:option&gt;
                                                  &lt;form:option value="3"&gt;3&lt;/form:option&gt;
                                                  &lt;form:option value="4"&gt;4&lt;/form:option&gt;
                                              &lt;/form:select&gt;
                                          &lt;/div&gt;
                                      &lt;/form&gt;--&gt;
                                      &lt;div class="select_md3 float-left"&gt;
                                          &lt;form:select path="day" id="birthDay" cssClass="select2" items="${days}"/&gt;
                                      &lt;/div&gt;
  
                                      &lt;span class="float-left f13 p_5"&gt;/&lt;/span&gt;  
                                      &lt;!--&lt;form method="post" action=""&gt;  
                                          &lt;div class="select_md3 float-left"&gt;
                                               &lt;form:select path="month" id="" cssClass="select2"&gt;
                                                  &lt;form:option value="1"&gt;1&lt;/form:option&gt;
                                                  &lt;form:option value="2"&gt;2&lt;/form:option&gt;
                                                  &lt;form:option value="3"&gt;3&lt;/form:option&gt;
                                                  &lt;form:option value="4"&gt;4&lt;/form:option&gt;
                                              &lt;/form:select&gt;
                                          &lt;/div&gt;
                                      &lt;/form&gt;--&gt;
                                      &lt;div class="select_md3 float-left"&gt;
                                          &lt;form:select path="month" id="birthMonth" cssClass="select2" items="${months}"/&gt;
                                      &lt;/div&gt;
                                      &lt;span class="float-left f13 p_5"&gt;/&lt;/span&gt;
                                      &lt;!--&lt;form method="post" action=""&gt;  
                                          &lt;div class="select_md4 float-left"&gt;
                                               &lt;form:select path="year" id="" cssClass="select2"&gt;
                                                  &lt;form:option value="1"&gt;2011&lt;/form:option&gt;
                                                  &lt;form:option value="2"&gt;2012&lt;/form:option&gt;
                                                  &lt;form:option value="3"&gt;2013&lt;/form:option&gt;
                                                  &lt;form:option value="4"&gt;2014&lt;/form:option&gt;
                                               &lt;/form:select&gt;
                                          &lt;/div&gt;
                                      &lt;/form&gt; --&gt;
                                      &lt;div class="select_md4 float-left"&gt;
                                          &lt;form:select path="year" id="birthYear" cssClass="select2" items="${years}"/&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.code" text="Code" var="phonecode"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="phoneCode" id="phoneCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${phonecode}"/&gt;
                                  &lt;/span&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.phonenumber" text="Phone Number" var ="phonenumber"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="phoneNumber" id="phoneNumber" cssClass="pd-form-txt-common pd-txt1 float-left shadow" placeholder="${phonenumber}"/&gt;
                                  &lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.code" text="Code" var="mobileCode"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="mobileCode" id="mobileCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${mobileCode}"/&gt;
                                  &lt;/span&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.mobilenumber" text="Mobile Number" var="mobileNumber"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="mobileNumber" id="mobileNumber" cssClass="pd-form-txt-common pd-txt4 float-left shadow"  placeholder="${mobileNumber}*"/&gt;
                                  &lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;form:select path="idDocument" cssClass="select-pd-name" id="idDocument"&gt;
                                      &lt;form:option value="0"&gt;&lt;spring:message code="myaccount.label.identificationdocument" text="Identification Document"&gt;&lt;/spring:message&gt;&lt;/form:option&gt;
                                      &lt;form:option value="1"&gt;&lt;spring:message code="myaccount.label.passport" text="Passport"&gt;&lt;/spring:message&gt;&lt;/form:option&gt;
                                      &lt;form:option value="2"&gt;&lt;spring:message code="myaccount.label.license" text="License"&gt;&lt;/spring:message&gt;&lt;/form:option&gt;
                                  &lt;/form:select&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;span class="f13 bold"&gt;&lt;spring:message code="myaccount.label.invoiceaddressforcompanies" text="Invoice Address for Companies"&gt;&lt;/spring:message&gt;&lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                &lt;form:input path="idNumber" cssClass="pd-form-txt-common pd-txt5 float-left shadow" placeholder="Ausweisnumber*"/&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;input type="checkbox" name="" class="mrgrgt5" id=" "&gt;&lt;span class="f13"&gt;&lt;spring:message code="myaccount.label.sameasmailaddress" text="Same as mail Address"&gt;&lt;/spring:message&gt; &lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;span class="f13 bold"&gt;&lt;spring:message code="myaccount.label.address" text="Address"&gt;&lt;/spring:message&gt;&lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.companyname" text="Company Name" var="companyname"&gt;&lt;/spring:message&gt;
                                      &lt;form:input id="companyName" path="companyName" class="pd-form-txt-common pd-txt2 float-left mrg-rgt10 shadow" placeholder="${companyname}"/&gt;
                                  &lt;/span&gt;                       
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;span&gt;
                                        &lt;spring:message code="myaccount.label.street" text="Street" var="${street}"&gt;&lt;/spring:message&gt;
                                        &lt;form:input path="address.street" id="street" cssClass="pd-form-txt-common pd-txt1 float-left mrg-rgt10 shadow" placeholder="${street}"/&gt;
                                  &lt;/span&gt;
                                  &lt;span&gt;
                                      &lt;form:input path="address.streetNo" id="streetNo" cssClass="pd-form-txt-common pd-txt3 float-left shadow" placeholder="No"/&gt;
                                  &lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;                                
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.street" text="Street" var="street"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="address.companyStreet" id="compStreet" cssClass="pd-form-txt-common pd-txt4 float-left mrg-rgt10 shadow" placeholder="${street}"/&gt;
                                  &lt;/span&gt;
                                  &lt;span&gt;
                                      &lt;form:input path="address.companyStreetNo" id="compStreetNo" cssClass="pd-form-txt-common pd-txt3 float-left shadow" placeholder="No"/&gt;
                                  &lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.plz" text="PLZ" var="zip"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="address.postalCode" id="postalCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${zip}"/&gt;
                                  &lt;/span&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.town" text="Town" var="compcity"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="address.city" id="city" cssClass="pd-form-txt-common pd-txt1 float-left shadow" placeholder="${compcity}"/&gt;
                                  &lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.plz" text="PLZ" var="plzcomp"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="address.companyPostalCode" id="compPostalCode" cssClass="pd-form-txt-common pd-txt3 float-left mrg-rgt10 shadow" placeholder="${plzcomp}"/&gt;
                                  &lt;/span&gt;
                                  &lt;span&gt;
                                      &lt;spring:message code="myaccount.label.town" text="Town" var="comtown"&gt;&lt;/spring:message&gt;
                                      &lt;form:input path="address.companyCity" id="compCity" cssClass="pd-form-txt-common pd-txt4 float-left shadow" placeholder="${comtown}"/&gt;
                                  &lt;/span&gt;                         
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;!--&lt;select class="select-pd-name" id="delivery_method" &gt;
                                      &lt;option class="select-pd-name" value="0"&gt;&lt;spring:message code="myaccount.label.country" text="Country"&gt;&lt;/spring:message&gt;&lt;/option&gt;
                                      &lt;option value="1"&gt;England&lt;/option&gt;
                                      &lt;option value="2"&gt;Irland&lt;/option&gt;
                                  &lt;/select&gt; --&gt;
                                  &lt;spring:message code="myaccount.label.country" text="Country" var="country"&gt;&lt;/spring:message&gt;
                                  &lt;form:input path="address.country" id="country" cssClass="select-pd-name" placeholder="${country}"/&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 "&gt;
                                  &lt;!--  &lt;select class="select-pd-name" id="delivery_method" &gt;
                                      &lt;option class="select-pd-name" value="0"&gt;&lt;spring:message code="myaccount.label.country" text="Country"&gt;&lt;/spring:message&gt;&lt;/option&gt;
                                      &lt;option value="1"&gt;England&lt;/option&gt;
                                      &lt;option value="2"&gt;Irland&lt;/option&gt;
                                  &lt;/select&gt;--&gt;
                                  &lt;spring:message code="myaccount.label.country" text="Country" var="compCountry"&gt;&lt;/spring:message&gt;
                                  &lt;form:input path="address.companyCountry" id="compCountry" cssClass="select-pd-name" placeholder="${compCountry}"/&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;                                               
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;select class="select-pd-name" id="delivery_method" &gt;
                                      &lt;option class="select-pd-name" value="0"&gt;&lt;spring:message code="myaccount.label.eticketidentification" text="E-ticket Identification"&gt;&lt;/spring:message&gt;&lt;/option&gt;
                                      &lt;option value="1"&gt;England&lt;/option&gt;
                                      &lt;option value="2"&gt;Irland&lt;/option&gt;
                                  &lt;/select&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 flt-rgt "&gt;
                                  &lt;spring:message code="myaccount.label.vatnumber" text="VAT Number" var="vatNumber"&gt;&lt;/spring:message&gt;
                                  &lt;form:input path="vatNumber" id="vatNumber" cssclass="pd-form-txt-common pd-txt2 float-left mrg-rgt10 shadow" placeholder="${vatNumber}"/&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;span class="f13 blue_txt"&gt;&lt;b&gt;*&lt;/b&gt;&lt;spring:message code="myaccount.label.fieldsmustbefilledout" text="Fields must be filled out"&gt;&lt;/spring:message&gt;&lt;/span&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 flt-rgt "&gt;
                                  &lt;input type="checkbox" name="" class="mrgrgt5"&gt;&lt;span class="f13"&gt;&lt;spring:message code="myaccount.label.futureinformationsofspecialofferings" text="I want to have in future informations about special of ferings for t4b customers."&gt;&lt;/spring:message&gt; &lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                          &lt;div class="comm_md m_top float-left"&gt;
                              &lt;div class="pd-colum1 mrg-rgt10"&gt;
                                  &lt;select class="select-pd-name" id="delivery_method" &gt;
                                      &lt;option class="select-pd-name" value="0"&gt;&lt;spring:message code="myaccount.label.languagepreferred" text="Language ,Preferred"&gt;&lt;/spring:message&gt;&lt;/option&gt;
                                      &lt;option value="1"&gt;Sizilian&lt;/option&gt;
                                      &lt;option value="2"&gt;English&lt;/option&gt;
                                  &lt;/select&gt;
                              &lt;/div&gt;
                              &lt;div class="pd-colum2 flt-rgt "&gt;
                                  &lt;input type="submit" name="" id="store" class="common-btn float-right" value="&lt;spring:message code="myaccount.label.store" text="Store"&gt;&lt;/spring:message&gt;" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;&lt;!--end row --&gt;
  
                      &lt;/div&gt;&lt;!--end pd-form-box --&gt;                      
                  &lt;/div&gt;
              &lt;/div&gt;
            &lt;/form:form&gt;
  </code></pre>
  
  <p>To solve this problem I have to use hidden form fields for username and password. Is there any other solution so the form fields not mentioned in jsp are not set to null?</p>
  
  <p>Below is my request handler after successful login</p>
  
  <pre><code>@RequestMapping(value = "/personaldata", method = RequestMethod.GET)
      public String personalData(Map&lt;String, Object&gt; map,
              HttpServletRequest request, Principal principal) {
          logger.info("Default Page");
  
          try {
              String userName = principal.getName();
              logger.debug("*******User name: " + userName);
              CustomerVO customerVO = customerService.findByUserName(userName);
              map.put("customerForm", customerVO);
          } catch (T4BException e) {
              logger.error(e.getLocalizedMessage());
          }
          /*
           * map.put("search", searchVO); if
           * (request.getParameter("ajax_get_standard_content") != null &amp;&amp;
           * request.getParameter("ajax_get_standard_content").equals("on")) {
           * return "home.definition.ajax"; } else { return "home.definition"; }
           */
          return "myaccount.personaldata";
      }
  </code></pre>
  
  <p>So, I add my backing bean in the model mao.</p>
  
  <p>Below is my request handler for update of data</p>
  
  <pre><code>    @RequestMapping(value = "/storepersonal", method = RequestMethod.POST)
          public String storePersonal(@ModelAttribute("customerForm")CustomerVO customerVO , Map&lt;String, Object&gt; map,
                  HttpServletRequest request, HttpSession session,Principal principal) {
          try {
              customerService.updateCustomer(customerVO);
              //map.put("customerForm", customerService.findByUserName(customerVO.getUserName()));
          } catch (T4BException e) {
              logger.error(e.getLocalizedMessage());
          }
  
      logger.info("Store Personal Page");
      /*
       * map.put("search", searchVO); if
       * (request.getParameter("ajax_get_standard_content") != null &amp;&amp;
       * request.getParameter("ajax_get_standard_content").equals("on")) {
       * return "home.definition.ajax"; } else { return "home.definition"; }
       */
      return "myaccount.personaldata";
  } 
  </code></pre>
  
  <p>The @ModelAtrribute specified for 'customerForm' should use the existing modelAttribute present in the model map as per documentation. So, only the form fields mentioned in jsp should be set to whatever user has enetered and remaining fields of customerForm should be as it is they were in the model map before.</p>