title: @ModelAttribute spring mvc portlets and ajax form submit
body: <p>Sorry for my poor english. I have many things going on in my mind which are confusing me literally. I want to handle the form submitted values as @ModelAttribute which is confusing me in the first place.
  Without using the @ModelAttribute I am good and have everything working perfectly.</p>
  
  <p>My requirements are to handle ajax form submit in portlets and spring mvc 3.0 annotations</p>
  
  <p>Form I have</p>
  
  <pre><code>&lt;portlet:resourceURL var="userURL" id="addUser" escapeXml="false" /&gt;
  
  &lt;form id="&lt;portlet:namespace /&gt;User&gt;
  &lt;table&gt;
  &lt;tr&gt;&lt;td&gt;First Name: &lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="fname"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Last Name: &lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="lname"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Address 1: &lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="address_1"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Address 2: &lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="address_2"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Zipcode &lt;/td&gt;
      &lt;td&gt;&lt;input type="text" name="zipcode"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&amp;nbsp; &lt;/td&gt;
      &lt;td&gt;&lt;button id="submit"&gt;Submit&lt;/td&gt;&lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I use the following jQuery to submit the form as an ajax call</p>
  
  <pre><code>$('#submit').on('click',function() {
     var fname = $('#fname').val();
     var lname = $('#lname').val();
     var address_1 = $('#address_1').val();
     var address_2 = $('#address_2').val();
     var zipcode = $('#zipcode').val();
  
     $.ajax({
        type: "POST"
        url: "&lt;c:out value="${userURL}" /&gt;"
        data: {fname: fname, lname: lname, address_1: address_1, address_2: address_2,         zipcode: zipcode }
        success: function(data) {
                     if(data == "success") {
                        $('#showError').hide();
                     } else {
                        $('#showError').show();
                     }
        } 
     })
  
  });
  </code></pre>
  
  <p>I have the following controller to handle the ajax call</p>
  
  <pre><code>@Controller
  @RequestMapping("VIEW")
  public class UserController {
  
         @ResourceMapping("addUser")
         public String addUser(ResourceRequest request, ResourceResponse response) {
              String fName = request.getParameter("fname");
              String lName = request.getParameter("lname");
              String address_1 = request.getParameter("address_1");
              String address_2 = request.getParameter("address_2");
              String zipcode = request.getParameter("zipcode");
  
              // I do the processing of the form and add the user attributes to the database.
         }
  
  }
  </code></pre>
  
  <p>I have created a User class and I want to use @ModelAttribute to set/get the values. I have gone through many links trying to figure out using it. One of the examples out uses the form taglib. I have jQuery to submit the form as an ajax call and  I am not sure if I change the form to this pattern it will break my code.</p>
  
  <pre><code>&lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;form:form method="post" action="addContact.html"&gt;
  
      &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="firstname"&gt;First Name&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="firstname" /&gt;&lt;/td&gt; 
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="lastname"&gt;Last Name&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="lastname" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="lastname"&gt;Email&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="email" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="lastname"&gt;Telephone&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="telephone" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan="2"&gt;
              &lt;input type="submit" value="Add Contact"/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;    
  
  &lt;/form:form&gt;
  </code></pre>
  
  <p>Thanks for the help!</p>