PDA

View Full Version : List in a command object


JEisen
Aug 10th, 2006, 12:06 PM
I've seen references that it's possible to have a command object contain a List, but can't seem to get it to work in practice.

Let's say I have object Foo. I have a form that takes a List<Foo> and outputs a form in the JSP.

<c:forEach var="foo" items="${model.fooList}">
<input type="text" name="fname" value="<c:out value='${foo.fname}'/>">
<input type="text" name="lname" value="<c:out value='${foo.lname}'/>">
</c:forEach>

Class Foo has properties fname and lname.
Command object FooCommand contains List<Foo>.

How do I bind this to the form so that the command object is filled correctly?

JEisen
Aug 10th, 2006, 02:38 PM
On the chance that I might be doing this in the completely wrong way, let me explain what I'm trying to do.

When a user logs in, they have a set of entries in a database for skills. I want to give them a form to edit all of those rows at once.

Internally, the skills are stored in a Skill object that I can pass around anywhere. So I'd like to have a List of Skill objects that's manipulatable.

I feel like this should be a rather simple, common task in Spring. All I want is something like the following, if I were coding all the pages by hand and interpreting the POSTs by hand.

<input name="name1" type="text" value="SkillName1">
<input name="level1" type="text" value="1">
<input name="name2" type="text" value="SkillName2">
<input name="level2" type="text" value="2">
<input name="name3" type="text" value="SkillName3">
<input name="level3" type="text" value="3">
<input name="name4" type="text" value="SkillName4">
<input name="level4" type="text" value="4">
<input name="name5" type="text" value="SkillName5">
<input name="level5" type="text" value="5">