Hi,
I wanted to handle a submitted form via a method like this (somewhat made up):
It turns out this does not quite work. Spring-MVC stores the submitted values into bean "pet" but also tries to submit the very same values in bean "owner". I do not fully understand why this is.Code:RequestMapping(method = RequestMethod.POST) public String addPetToOwner(ModelAttribute("pet") Pet pet, BindingResult result, ModelAttribute("owner") Owner owner) {...}
Looking at the 2.5.5 code it seems like lines 209-210 in file HandlerMethodInvoker are responsible for this. I do not understand why these lines are needed.
Why not simply use the convention that the object to receive the submission is the one preceeding the BindingResult? This way other arguments annotated as ModelAttributes can be left as is and receive the intended data (in the example above it might be an Owner instance created earlier and annotated as a SessionAttribute).


Reply With Quote