I've got a DTO (bean) with ArrayList field:
public MyDTO {
...
private List<MyThing> things;
...
... getters, setters and so on
}
In my initBinder I have:
@InitBinder
public void initBinder(WebDataBinder binder) {
...
binder.registerCustomEditor(List.class, "things", new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
List<MyThing> things = new ArrayList<MyThings>;
// fill things array with data from text
...
// On that stage things value is correct!
super.setValue(things);
}
});
}
And in my controller request method:
@RequestMapping({"save"})
public ModelAndView doSaveMyDTO(@ModelAttribute MyDTO myDTO) {
// very strange myDTO comes here=(
}
The problem is that while I'm in registerCustomEditor staff the things array is ok.
But when I get to the doSaveMyDTO method - MyDTO.things looks like Array of one element arrays of actual values:
Expected (things in initBinder):
[value1, value2, value3]
Get in doSaveMyDTO (myDTO.getThings()):
[[value1], [value2], [value3]]
Why? Please explain...