Announcement Announcement Module
Collapse
No announcement yet.
@ModelAttribute in its own @Controller? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ModelAttribute in its own @Controller?

    I have 'normal' @Controllers with @RequestMappings that are working just fine - including the bindings to @ModelAttribute backing beans.

    However, I also have other @Controllers which only contain @ModelAttribute annotated methods returning reference data; e.g.

    Code:
    @Controller
    public class StaticValuesController {
    
        @ModelAttribute("possiblePageSizes")
        public int[] getPossiblePageSizes() {
            return new int[] {5, 10, 20, 25};
        }
    
    }
    The above is referenced in a view, the following way:

    HTML Code:
    <form:select items="${possiblePageSizes}" path="pageSize" onchange="this.form.submit()" />
    However, the select is not being populated.

    Is my approach obviously incorrect?

  • #2
    Is my approach obviously incorrect?
    It is... @Controllers without @RequestMappings are useless as they are mapped to nothing. Add the @ModelAttribute to the controllers that need it. If it is something that needs to be available to all controllers/views add a HandlerInterceptor.

    Comment


    • #3
      OK - Thanks! The intent was exactly as you said - to share among several (if not all) @Controllers. I'll look into HandlerInterceptor.

      Comment

      Working...
      X