Results 1 to 4 of 4

Thread: Annotations + pagination

  1. #1

    Default Annotations + pagination

    Hi,

    I used to use handle() or formBackingObject() (from SimpleFormController) to handle pagination on pages including a form to change the results at anytime.
    For instance let's say I want to display a list of cities according to the State: I have a simple form at the top of my page with a list of States and a submit button, and on the same page a list of 10 cities, so I can change the State at anytime, that refreshes the results (the 10 first cities), and on the same page I have a "next" and "previous" button at the bottom to display other cities.
    So that means my controller has to be able to accept either POST or GET data but to display the "same thing", also I have to be able to handle the first call to the page, that initializes my form with default values, in my case a default State (and the cities related).

    What is the correct way to do that with annotations in a @Controller, using @RequestMapping(method = ...) etc. ? I am confused by the way to mix everything.

    Thank you.

  2. #2
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default

    If you are allowed to use Javascript then I would make a AJAX call to refresh the cities based upon the state that the user has selected.

  3. #3

    Default

    I can not use Ajax. Anyway even if I could, there must be a way to do that properly with 1 controller.
    The thing is Spring docs or tutorials cover only the simplest cases and it's always a pain in the butt to make things a little bit more complex (but common) work, or to get recommendations for good practice.

  4. #4
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default

    I misunderstood what you are looking for. If you need a controller method to handle both "GET" and "POST" methods as well as pagination then this should do it. Keep in mind that you have not posted any of your current code so I am assuming a good bit here:

    Code:
    @RequestMapping(value = "/viewCities", method = {RequestMethod.GET, RequestMethod.POST})
    public String viewCities(
        @RequestParam(value="stateId",required=false) String stateId,
        @RequestParam(value="pageVal",required=false, default="1") Integer pageVal) {
    }

Posting Permissions

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