PDA

View Full Version : Q: spring:bind with a simple List<String>


Dari
Aug 11th, 2007, 10:43 AM
i have a simple question.
how can i bind a simle List with Strings on my formBackingObject?

my formbackingObject contains a

public class SimpleBean {
private List<String> names;

public void setName(List<String> names) {
this.name = name;
}

public List<String>getNames() {
return names;
}
}


in my controller i fill this List with 8 new Strings:

protected SimpleBean formBackingObject(HttpServletRequest request) throws Exception {
SimpleBean bean = (SimpleBean)super.formBackingObject(request);
List<String> names = new ArrayList<String>();
for(int i=0; i<8; i++){
names.add(new String() );
}
bean.setNames(names);

return bean;
}


now i bind 8 textfieldes on this List in my jspFile:

...
<spring:bind path="bean.names[3]">
<input type="text" name="name4" /><br>
<font color="red"><c:out value="${status.errorMessage}"/> </font>
</spring:bind>

<spring:bind path="bean.names[4]">
<input type="text" name="name5" /><br>
<font color="red"><c:out value="${status.errorMessage}"/> </font>
</spring:bind>
...


i know its very static, but its a simple example.

when my Controller give me back the filled formbacking object in the method "protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception ",
the List with the Strings are every time empty

where is the mistake?
thanks for your replies

jglynn
Aug 11th, 2007, 02:37 PM
Try this.

...
<spring:bind path="bean.names[3]">
<input type="text" name="${status.expression}" /><br>
<font color="red"><c:out value="${status.errorMessage}"/> </font>
</spring:bind>

<spring:bind path="bean.names[4]">
<input type="text" name="${status.expression}" /><br>
<font color="red"><c:out value="${status.errorMessage}"/> </font>
</spring:bind>
...