I want to send a list of object id's (generated by the user selecting checkboxes) by POST to an action, so I can get a java.util.List<MyObject> converted using an MyObjectEditor.
So, is it possible to do this?
@InitBinder
public void initBinder (WebDataBinder binder) {
binder.registerCustomEditor(MyObject.class, new MyObjectEditor());
}
@RequestMapping (value = "", method = RequestMethod.POST)
public String action (@RequestParam List<MyObject> myList, Model model) {
// more stuff here
}
And my POST would be like this:
myList[0] = 12
myList[1] = 15
myList[2] = 7
Thanks!
This kind of binding is not supported by @RequestParam, so you have to use @ModelAttribute:
class MyObjects {
private List<MyObject> myList;
...
}
public String action (@ModelAttribute MyObjects myObjects, Model model) { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With