Listing 6-19.NestedSetCommandBean Class
public class NestedSetCommandBean {
Set<Name> names = new LinkedHashSet<Name>();
Set<String> strings = new LinkedHashSet<String>();
public NestedSetCommandBean() {
names.add(new Name());
strings.add("first string");
}
public Set<Name> getNames() {
return names;
}
public void setNames(Set<Name> names) {
this.names = names;
}
public Set<String> getStrings() {
return strings;
}
public void setStrings(Set<String> strings) {
this.strings = strings;
}
}
The following unit test, Listing 6-20, illustrates the limits of using the DataBinderwith a
Setby showing what ispossible.
Listing 6-20.NestedSetCommandBean Unit Test
public void setUp() throws Exception {
bean = new NestedSetCommandBean();
binder = new ServletRequestDataBinder(bean, "beanName");
request = new MockHttpServletRequest();
}
public void testSimpleBind() {
// just like /servlet?names[0].firstName=Anya&names[0].lastName=Lala
request.addParameter("names[0].firstName", "Anya");
request.addParameter("names[0].lastName", "Lala");
binder.bind(request);
134 CHAPTER 6 ■THE CONTROLLER MENAGERIE