title: ModelAttribute returns null values in controller in Spring MVC
body: <p>Ok, its time to seek help; I am sending a (shopping) Cart ModelAttribute to my jsp, allowing the user to edit the quantity, when the Model is POST to the controller the fields are null except the editable (quantity) field. I have researched for days on similar issues but nothing is matching. I am using spring 3.1.</p>
  
  <p>Here is my controller on the GET and POST:</p>
  
  <pre><code>@Controller
  public class CartController {
  
        @Autowired
        private Cart cart;        
  
        @RequestMapping(value = "/cart", method = RequestMethod.GET)  
        public String showCart(Model model) {
           logger.debug("CartController.showCart() Cart: {}", this.cart);
           model.addAttribute(cart);
           return "cart/cart";
        }
  </code></pre>
  
  <p>and POST</p>
  
  <pre><code>   @RequestMapping(value = "/cart", method = RequestMethod.POST, params = "update")
     public String update(@ModelAttribute("cart") Cart cart, BindingResult result, Model model) {
        logger.debug("CartController.update() Cart: {}", cart); 
        return "cart/cart";
     }
  </code></pre>
  
  <p>my jsp:</p>
  
  <pre><code>&lt;div class="container MainContent"&gt;
     &lt;form:form method="POST" modelAttribute="cart"&gt;
        &lt;fieldset&gt;
           &lt;legend&gt;Cart&lt;/legend&gt;
           &lt;table class="table"&gt;
              &lt;thead&gt;
                 &lt;tr&gt;
                    &lt;th&gt;Product Name&lt;/th&gt;
                    &lt;th&gt;Quantity&lt;/th&gt;
                    &lt;th&gt;Product Price&lt;/th&gt;
                 &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                 &lt;c:forEach items="${cart.cartDetails}" var="cartDetail" varStatus="status"&gt;
                    &lt;tr&gt;
                       &lt;td&gt;${cartDetail.product.name}&lt;/td&gt;                     
                       &lt;td&gt;&lt;form:input path="cartDetails[${status.index}].quantity" size="1" /&gt;&lt;/td&gt;                     
                       &lt;td&gt;${cartDetail.price}&lt;/td&gt;
                 &lt;/c:forEach&gt;
                 &lt;tr&gt;
                    &lt;b&gt;&lt;td colspan="2" align="right"&gt;&lt;spring:message code="order.total" /&gt;&lt;/b&gt;
                    &lt;/td&gt;
                    &lt;td&gt;${cart.totalCartPrice}&lt;/td&gt;
                 &lt;/tr&gt;
              &lt;/tbody&gt;
           &lt;/table&gt;
        &lt;/fieldset&gt;
        &lt;div&gt;&lt;/div&gt;
        &lt;button id="order" name="order"&gt;
           &lt;spring:message code="button.order" /&gt;
        &lt;/button&gt;
        &lt;button id="update" name="update"&gt;
           &lt;spring:message code="button.update" /&gt;
        &lt;/button&gt;
     &lt;/form:form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and the log results for cart before on GET:</p>
  
  <blockquote>
    <p>CartController.showCart() Cart: Cart [cartDetails=[CartDetail
    product=com.Product@c26440[name=My Name],
    quantity=1]], totalCartPrice=10.00]</p>
  </blockquote>
  
  <p>and after updating the quantity from 1 to 3 in the jsp and then POST to the controller:</p>
  
  <blockquote>
    <p>CartController.update() Cart: Cart [cartDetails=[CartDetail
    [product=null, quantity=3]], totalCartPrice=null]</p>
  </blockquote>
  
  <p>I've read several similar post here and on the Spring forum and tried different suggested solutions with no luck. It seems like my edited quantity results are getting bound to the Object correctly but why aren’t the others?  </p>