Announcement Announcement Module
Collapse
No announcement yet.
Annotation Help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Annotation Help

    I have a controller which has a few actions, which are triggered by hitting various buttons on the page. I would like to have a default action, but am unsure how to annotate the method. Here is an example:
    Code:
    @Controller
    @RequestMapping("/view.jsp")
    public class ExampleController {
    
        @RequestMapping(method = RequestMethod.GET)
        public ModelAndView displayResults() {
            ModelAndView mav = new ModelAndView("view");
            mav.addObject("queryResults", methodToQueryDBForListing());
            return mav;
        }
    
        @RequestMapping(method = RequestMethod.POST, params="submit=Action 1")
        public ModelAndView action1(@RequestParam("selectedItemKey") String key) {
            ModelAndView mav = new ModelAndView("action1");
            //Business logic
            return mav;
        }
    
        @RequestMapping(method = RequestMethod.POST, params="submit=Action 2")
        public ModelAndView action2(@RequestParam("selectedItemKey") String key) {
            ModelAndView mav = new ModelAndView("action2");
            //Business logic
            return mav;
        }
      
        //A few more methods which basically do what action1 and action2 do
    }
    How can I annotate a method which will act on a POST with any submit button pressed with no key selected?

    I have tried:

    Code:
    @RequestMethod(method = RequestMethod.POST, params="!selectedItemKey")
    @RequestMethod(method = RequestMethod.POST)
    I'd really hate it if I had to set required = false on each of the methods which take RequestParams and then conditionally check to see if one comes in or not... Is there a way to annotate this to work properly?

  • #2
    Resolved

    @RequestMapping(method = RequestMethod.POST, params= {"!selectedItemKey" , "submit"})

    It seems odd though, that the method with just "!selectedItemKey" wasn't selected after the other candidates were disallowed due to the required param not existing.

    Perhaps I should file a bug.

    Comment

    Working...
    X