Results 1 to 3 of 3

Thread: @RequestParam with custom object

  1. #1
    Join Date
    Nov 2005
    Posts
    15

    Default @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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You give the solution yourself already. Use a @ModelAttribute...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2005
    Posts
    15

    Default

    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 .

Posting Permissions

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