title: Spring MVC - accessing objects from a list in JSP for a form
body: <p>I am trying to create a form with multiple objects being passed.
  I am trying to create a form where you can find '<code>product</code>' and '<code>customer</code>' and add them to order.
  I have 2 model classes <code>Customer</code> and <code>Product</code>. <code>Customer</code> has <code>phoneNo</code> variable, <code>Product</code> has <code>name</code> variable.
  I found that easiest way to pass multiple objects is to add them to list and pass <code>List</code> to a <code>View</code>. That's what I'm doing, but accessing those model objects is a different story.</p>
  
  <p><strong>Controller class:</strong></p>
  
  <pre><code> @Controller
      public class OrderController {
  
      @RequestMapping(value="/create_order", method= RequestMethod.GET)
      public ModelAndView create_order() {
          Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
          model.put("customer", new Customer());
          model.put("product", new Product());
  
  
          return new ModelAndView("create_order", "command", model);
      }
      }
  </code></pre>
  
  <p><strong>Page:</strong></p>
  
  <pre><code>&lt;form:form method="POST" action="/Persistence_Web/order_confirmation" commandName="model"&gt;
  &lt;table&gt;
  &lt;!-- I tried few different ways of writing it and all fail --&gt;
      &lt;tr&gt;&lt;form:label path="model[0].phoneNo"&gt;Customer phone number&lt;/form:label&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;form:input path="model[0].phoneNo"&gt;&lt;/form:input&gt;&lt;/tr&gt;
  ....
  </code></pre>