Reputation: 18330
we have a list of domain objects needing to be edited on an html page. For example, the command & domain objects:
class MyCommand {
List<Person> persons;
}
class Person {
String fname;
String lname;
}
Then, the HTML I expect to have the Spring MVC tag libraries generate is like this:
<form>
<input name="persons[0].fname"> <input name="persons[0].lname"><br/>
<input name="persons[1].fname"> <input name="persons[1].lname"><br/>
<input name="persons[2].fname"> <input name="persons[2].lname"><br/>
...
<input name="persons[n].fname"> <input name="persons[n].lname"><br/>
</form>
But can't see how to express this using the Spring Form Tag Libraries (using Spring 2.5.6.). I want to use the tag libraries so that it takes care of binding existing values to the tags for editing (when they're there).
Any tips?
Upvotes: 1
Views: 1162
Reputation: 51062
There isn't a way to simply have the Spring Form Tags generate the whole list based on the collection (it will do this for the options in a select box, but that's the only collection-based expansion I'm aware of). However, you can still use the Spring Form Tags within a loop like so:
<c:forEach var="person" varStatus="loopStatus" items="myCommand.persons">
<form:input path="persons[${loopStatus.index}].fname" /> <form:input path="persons[${loopStatus.index}].lname" /><br />
</c:forEach>
Upvotes: 2