I have the following pojo:
public class Foo {
@Size(min=0,max=10)
private String bar = null;
@Size(min=0,max=10)
private String baz = null;
.... getters and setters
}
and the following Controller:
@Controller
@RequestMapping(value = "/path", method = RequestMethod.POST)
public class Control {
public String handler(@Valid Foo foo1, BindingResult res_foo1, @Valid Foo foo2, BindingResult res_foo2){
//Business logic
}
}
and the following form snippet:
<form action="/path">
<input name="foo1.bar" type="text" />
<input name="foo1.baz" type="text" />
<input name="foo2.bar" type="text" />
<input name="foo2.baz" type="text" />
</form>
I get the following error when submitting the form:
java.lang.IllegalArgumentException: argument type mismatch
If the objects are different and the pojos have different properties it works fine. Is there a way to make this work?
I just figured it out. The trick is to nest the pojos into another pojo.
use a controller like this:
and a form like this:
This does make validating the two objects separately, impossible.