Thanks Marten
I really appreciate your response. I'm delighted to hear that we don't need a dedicated bean for each form.
I was able to use User as the form as so:
The form:
Code:
<form:form commandName="userForm" method="POST" action="edituser.htm">
<form:select path="country.id" >
<form:options items="${countryList}" itemValue="id" itemLabel="name" />
</form:select>
That actually automatically causes a new instance of Country to be set in User having the correct id.
User bean
Code:
public class User {
private long id;
private String name;
private Country country;
getters and setters
The controller
Code:
@RequestMapping( method= RequestMethod.GET )
public String showForm(Map model) {
if( !model.containsAttribute("userForm") )
model.put("userForm", new User() );
model.put( "countryList", Util.getCountyList() );
return "edituser";
}
public String submitForm(@ModelAttribute("userForm") User cmd, BindingResult result, Map model) {
if cmd has validation issues {
return showForm(model);
} else {
return "redirect:/index.htm";
}
}
I'm now looking into the @Valid feature and making (proper) use of BindingResult.
For a newbe like myself, I'd love to hear of any spring 3 features that you/anybody would consider essential to know and use in the building of any web application. Any thoughts and comments welcome please.
Thanks very much
J