Announcement Announcement Module
Collapse
No announcement yet.
@ModelAttribute: Interactions between 'referenceData' and 'formBackingObject' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ModelAttribute: Interactions between 'referenceData' and 'formBackingObject'

    I'm trying to convert our most complicated spring 2 controller to spring 3 with annotations. This controller has a ton of reference data, and some of it needs a loaded model to do its thing.

    The issue I'm having is that once a referenceData style method includes the model as a parameter, the method for that model is no longer called.

    Here are some snippets:
    Code:
        // reference data
        @ModelAttribute("packages")
        public List<StretchPackage> getPackages(@ModelAttribute("eventModelObj") EventModel model){
            return packageDao.getForUser(model.getClientId());
        }
        
        // form backing object
        // This is invoked when getPackages does NOT have the model passed to it
        // If i remove it from getPackages(), or rename it to @ModelAttribute("eventModelObj111") it is invoked
        @ModelAttribute("eventModelObj")
        public EventModel formBackingObject(HttpServletRequest request){
            EventModel model = new EventModel();
            // do lots of stuff
            return model;
        }
    I'm pretty sure I'm not doing this the right way, but the documentation is light on information. Is it possible to have a 'referenceData' method use the form backing object? If so, how?

  • #2
    I figured out what was wrong... I was missing an annotation at the class level:


    Code:
    @Controller
    @SessionAttributes("eventModelObj")
    public class EventEditorController {
    Adding the @SessionAttributes annotation causes it to work as expected.

    Comment

    Working...
    X