Announcement Announcement Module
No announcement yet.
Spring 2.5 controller question Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

    @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
    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
      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
        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.


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