title: Keep value in model attribute for spring mvc
body: <p>When I'm using a Spring MVC controller and I submit a form by setting value to the <code>modelAttribute</code> I lose some of the model's fields which are not mapped in the form.
  In this example, because I didn't map age and address, these user's fields are lost and so they have <code>null</code> value. I don't want to let the user change their age and the address, that's why these fields are not in the form.</p>
  
  <p>Method controller to post user edit form:</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = "/edit", method = RequestMethod.POST)
  public String editionUser(Model model, @ModelAttribute("accountForm") User user,
    BindingResult bresult,
    RedirectAttributes redirectAttributes) {
    //user.getAge() and user.getAddress are null           
  
    //Save the information...
  }
  </code></pre>
  
  <p>Method controller to get edit user page:</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = "/edit", method = RequestMethod.GET)
  public String initEdit(Model model) {
    // the user fields are all filled
    User user = userService.getUserById(...);
    model.addAttribute("accountForm", user);
    return "edition";
  }
  
  
  class User {
    Long id;
    String email;
    String age;
    String address;
    String nickname;
  
    // ...
  }
  </code></pre>
  
  <p><strong>edition.jsp</strong> </p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;form:form class="form" method="POST" action="edition" modelAttribute="accountForm"&gt;
    &lt;form:label path="email"&gt;email&lt;/form:label&gt;
    &lt;form:input path="email"  name='email'/&gt;
    &lt;form:label path="nickname"&gt;nickname&lt;/form:label&gt;
    &lt;form:input path="nickname"  name='nickname'/&gt;
    &lt;form:hidden path="id" /&gt;
    &lt;input name="submit" type="submit"    value="valid" /&gt;  
  &lt;/form:form&gt;
  </code></pre>
  
  <p>What are the best solution to not lose the value of these fields ? (age and address)</p>
  
  <p>Use form hidden path for each field ?? 
  Store the user in session before redirect to the edit page and set retreive the user session in post method controller to only change the modified fields ?
  Is there a generic method?</p>