Announcement Announcement Module
No announcement yet.
@ModelAttribute in its own @Controller? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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.

    public class StaticValuesController {
        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.


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