I have a controller with 2 methods that return related objects via the @ModelAttribute annotation:
These objects are related to each other with one Site having many Documents. This relationship is mapped in JPA. Both of these objects contain a field with the same name, called "urlAlias". This field is edited on a page using the following freemarker markup:Code:@ModelAttribute("site") public Site getSite(){ ..... return site; } @ModelAttribute("document") public Document getDocument(){ ..... return document; }
When I submit the form to the controller, I retrieve the document object using the following syntax:Code:<@spring.bind "document" /> .... <@spring.formInput "document.urlAlias" />
It appears that any value that I enter into the Document's urlAlias field has also been set in the Site object, even though I only edited the value of the field in the Document object.Code:@RequestMapping(method = RequestMethod.POST) public ModelAndView create(@ModelAttribute("document") @Valid Document document, BindingResult documentResult, @ModelAttribute("site") Site site, Model model){ ...Do Stuff... }
I'm perplexed as to what is going on here. Am I doing something untoward by mapping more than one ModelAttribute in the same controller? Are there any other likely causes of this behaviour?


Reply With Quote
