I have the Person & Fruit bean defined like this:
public class Person {
private String fullName;
private List<Fruit> favoriteFruits;
//getters setters and constructors here.
...
}
public class Fruit {
private String name;
//getter setter and constructors here.
}
Then I have a Struts2 Action like this:
public class AddPersonAction extends ActionSupport {
private static final long serialVersionUID = -1856680463263215989L;
private Person person;
@Override
public String execute() throws Exception {
if (person!= null) {
//TODO add person to database.
return SUCCESS;
} else {
return INPUT;
}
}
}
And the Strus2 html form looks like this:
...
<form...>
<s:textfield name="person.fullName"/>
<!--This is where I would allow user to create one or more textboxes using javascript.
And allow them to input multiple favorite fruits -->
<s:submit name="submit" value="Submit" />
</form>
...
Now, my question, the way I have mapped textfield named person.fullName
directly to the Person bean's fullName
property, how can I map the multiple textboxes (favorite fruit) to the Person bean's favoriteFruits
collection (List<Fruit>
) ?