Using initBinder() in the form controller (or whatever other command controller) you can register your own custom property editors. Using those you can resolve other than primitive types.
Implement PropertyEditorSupport and override setAsText and getAsText:
Code:
DriverEditor extends PropertyEditorSupport {
public void setAsText(String text) {
// text is the string from the form, for example an identifier in
// the database
// use whatever you like to retrieve the appropriate Driver object
Driver d; // retrieve
setValue(d);
}
public String getAsText(Object value) {
Driver d = (Driver)value);
return d.getId(); // for example
}
}
Let's say your command name is car.
Code:
<select name="car.driver">
<option value="1">Driver one</option>
<option value="2">Driver two</option>
</select>
1 resp. 2 would be the String passed to your custom editor.
Finally, register your editor using
Code:
binder.registerCustomEditor(Driver.class, "driver" /* this is optional */, new DriverEditor());
Hope this helps.
Alef