Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.0 MVC @ModelAttribute - order of properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.0 MVC @ModelAttribute - order of properties

    Hello,

    I use a controller class that has a method with a @ModelAttribute parameter:

    Code:
    @Controller()
    public class SomeController {
    
      @RequestMapping({ "/show" })
      public ModelAndView show(@ModelAttribute("entry") SomeEntry entry) {
        return new ModelAndView("show");
      }
    
    }
    Code:
    public class SomeEntry {
      
      private String a;
      private String b;
      private String c;
    
      public String getA() {
        return a;
      }
    
      public void setA(String a) {
        this.a = a;
      }
    
      public String getB() {
        return b;
      }
    
      public void setB(String b) {
        this.b = b;
      }
    
      public String getC() {
        return c;
      }
    
      public void setC(String c) {
        this.c = c;
      }
    
    }
    When the @ModelAttribute "entry" is filled in a POST request, the setters of "entry" are called in the following order:
    1. setA
    2. setB
    3. setC

    Can I specify in which order the setters are called? For example:
    1. setC
    2. setA
    3. setB

    Regards
    Thomas

  • #2
    No, you can't do it. The order come from request.getParameterMap().entrySet()

    Comment


    • #3
      Ok.

      I have to ensure that, in my example, setC is called before setA. Is there any way to do that?

      Comment


      • #4
        Bind parameters to variables and fill your model in the order that you want.
        Last edited by chelu; Jan 25th, 2012, 05:32 AM.

        Comment

        Working...
        X