Results 1 to 5 of 5

Thread: Spring 2.5 controller question

  1. #1

    Default Spring 2.5 controller question

    if I have the following controller, how do you handle multiple buttons on the same page that do a post? For example, I might might add an additional post method to AddOwnerForm - but I am not sure how spring would differentiate between the various post methods. The only thing I can think of is change the RequestMapping to /addOwner/* and change the post url in javascript when a button is clicked.

    @Controller
    @RequestMapping("/addOwner.do")
    @SessionAttributes(types = Owner.class)
    public class AddOwnerForm {

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(Model model) { ... }


    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@ModelAttribute Owner owner, BindingResult result, SessionStatus status) { ... }

    }

  2. #2
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Would the stuff on page 347 (pdf) of the Spring Reference Documentation work for you? That's where they have multiple @RequestMapping annotations on methods, rather than on the class, and the @RequestMapping annotations specify urls, not request methods. There are no @RequestMapping annotations that specify the request method.

    I've never used that way so I have no idea how it works.

  3. #3

    Default

    not really, because if you have a form, the url is already set to where it will post to, lets say /accounts/create. If you have multiple buttons in that form - it will still go to that url unless you change the form url when a button is clicked. Stripes, an alternate mvc solution, uses the button name to indicated what method to call on the controller - is this something that will be in spring mvc 3.0?

  4. #4
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Sure, note this section from the docs:
    Path mappings can be narrowed through parameter conditions: a sequence of "myParam=myValue" style expressions, with a request only mapped if each such parameter is found to have the given value. "myParam" style expressions are also supported, with such parameters having to be present in the request (allowed to have any value). Finally, "!myParam" style expressions indicate that the specified parameter is not supposed to be present in the request.
    Since the button name clicked is exposed as a request param, it should be easy to set up this type of parameter expression matching on your request handler methods.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  5. #5
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Nice; I missed that. It's at the top of page 348 of the pdf.

Posting Permissions

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