Results 1 to 4 of 4

Thread: Spring 3.0 MVC @ModelAttribute - order of properties

  1. #1
    Join Date
    Jan 2012
    Posts
    2

    Question 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. #2
    Join Date
    Apr 2008
    Location
    Seville, Spain
    Posts
    132

    Default

    No, you can't do it. The order come from request.getParameterMap().entrySet()
    Jose Luis Martin
    Freelance Senior Consultant
    JDAL - Java Database Application Library

  3. #3
    Join Date
    Jan 2012
    Posts
    2

    Default

    Ok.

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

  4. #4
    Join Date
    Apr 2008
    Location
    Seville, Spain
    Posts
    132

    Default

    Bind parameters to variables and fill your model in the order that you want.
    Last edited by chelu; Jan 25th, 2012 at 04:32 AM.
    Jose Luis Martin
    Freelance Senior Consultant
    JDAL - Java Database Application Library

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •