java - Spring MVC - accessing objects from a list in JSP for a form -


i trying create form multiple objects being passed. trying create form can find 'product' , 'customer' , add them order. have 2 model classes customer , product. customer has phoneno variable, product has name variable. found easiest way pass multiple objects add them list , pass list view. that's i'm doing, accessing model objects different story.

controller class:

 @controller     public class ordercontroller {      @requestmapping(value="/create_order", method= requestmethod.get)     public modelandview create_order() {         map<string, object> model = new hashmap<string, object>();         model.put("customer", new customer());         model.put("product", new product());           return new modelandview("create_order", "command", model);     }     } 

page:

<form:form method="post" action="/persistence_web/order_confirmation" commandname="model"> <table> <!-- tried few different ways of writing , fail -->     <tr><form:label path="model[0].phoneno">customer phone number</form:label></tr>     <tr><form:input path="model[0].phoneno"></form:input></tr> .... 

to refer attributes product.name , customer.phoneno in model, have refer names give in model plus attribute name (that must have getter in class!!!)

<tr><form:input path="${customer.phoneno}"></form:input></tr> <tr><form:input path="${product.name}"></form:input></tr> 

*the attributes in classes must have getters , setters if want manipulate them in view. naming must be:

private int attributename public  int getattributename() 

but: long getter method in class variable name in view. can have getmycalculation() method without mycalculation attribute in order calculate totals, averages, formatting dates, or whatever need show in view not store in model.

also, various products or customers use list:

list<customer> customers = // fill list!!! model.put("customers", customers); 

and iterate <for:earch>

<c:foreach items="${customers}" var="customer">          <c:out value="${customer.phoneno}"/> </c:foreach>