Announcement Announcement Module
Collapse
No announcement yet.
@RequestParam with custom object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RequestParam with custom object

    I have an 'advanced search' page (A) that needs to submit (using GET method) to a Controller. In the end, that controller should forward to an 'advanced search result' page (B). But the problem is that there are lots of request parameters to declare in the controller's handler method... It'd be nice if there is some way to bind all the parameters of request to an custom object (like @ModelAttribute) by using @RequestParam. Is that possible?

    Ugly code:
    Code:
        @RequestMapping(method = RequestMethod.GET)
        public String search(@RequestParam("a") String a, @RequestParam("b") int b, @RequestParam("c") long c, @RequestParam("d") String d, @RequestParam("e") String e, @RequestParam("f") String f, @RequestParam("g") String g, @RequestParam("h") String h)
    {
    
    ...
    }

  • #2
    You give the solution yourself already. Use a @ModelAttribute...

    Comment


    • #3
      Ok. But if I use @ModelAttribute (and binding to the form inputs) how can I redirect (GET) again to 'search result page' after some POST by keeping all check boxes checked or unchecked depending on the query parameters? I don't want to couple the application to Spring by creating new hidden inputs and adding "_" prefix to id of all check boxes with 'on' value .

      Comment

      Working...
      X