Announcement Announcement Module
No announcement yet.
Need help setting a model attribute from a session attribute Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help setting a model attribute from a session attribute

    I'm using Spring 3, and my scenario is I've got a web app (working well) which may display a dropdown select in the header on several pages (I'm reusing the header page with the form across these pages).

    I'm using a form:form for this, and I have the object I want to use for my modelAttribute in scope in session. However I'm running into the "Neither BindingResult nor plain target object for bean name as request attribute" exception. I recognize the problem is I'm not explicitly setting my modelAttribute in my controller before the form is presented.

    The pages on which this header may appear have different controllers with different model attributes. I do not wish to contaminate them with set-up for the select's model attribute.

    I am handling the select's form within a separate controller, which is invoked when the selection changes. I am wondering what the best approach to this is, where there is a separate form across multiple pages which requires setup, yet we're not hitting its controller until the form is submitted. Surely this is a common scenario? Is there an easy solution to this? Some quick way, preferably in the jsp, to tell the form to use a certain attribute as the model rather than having to hit a controller first?

    If not, I'll have to revert to a vanilla form, and forgo the nice binding I get through the model attribute and the spring form.

  • #2
    I am an idiot. I solved this before I left for vacation and forgot all about it.

    I was using a HandlerInterceptor's postHandle() method to conditionally add the desired model. I'd love to know of there are any better approaches, however.