Using pagging techniques - V

2 August 2008

We set the start and range parameters for the pagination tag. We could have made the tag read from the request but it is not done because the search action could be redirecting to the JSP page instead of forwarding. The pagination tag preserves all the request parameters.

If you are using the Struts framework, then design the search action in such a way that you would read the start and range parameters from the request and pass them to the DAO, which executes a limiting query equivalent to the one above and returns the relevant results for the start and range. Example snippet is given below:

// NumberUtils is part of Jakarata-commons-lang. Please download Jakarta commons-lang. 
  public class PaginationAction extends Action {
    public static final String SUCCESS = "success";
      public ActionForward execute(
        ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {
        PageDAO pageDAO = DAOFactory.getDAOFactory(Factory.MySQL).getPageDAO();
        int start = NumberUtils.stringToInt(((PaginationForm) form).getStart(), 0);
        int range = NumberUtils.stringToInt(((PaginationForm) form).getRange(), 10);
 
        ((PaginationForm) form).setList(pageDAO.getList(start, range)); // Setting the list
        ((PaginationForm) form).setResults(    //Setting the total number of results
        String.valueOf(pageDAO.getTotalNumberOfResults()));
        return mapping.findForward(SUCCESS);
    }
  }

continued …

del.icio.us:Using pagging techniques - V  digg:Using pagging techniques - V  spurl:Using pagging techniques - V  wists:Using pagging techniques - V  simpy:Using pagging techniques - V  newsvine:Using pagging techniques - V  blinklist:Using pagging techniques - V  furl:Using pagging techniques - V  reddit:Using pagging techniques - V  fark:Using pagging techniques - V  blogmarks:Using pagging techniques - V  Y!:Using pagging techniques - V  smarking:Using pagging techniques - V  magnolia:Using pagging techniques - V  segnalo:Using pagging techniques - V  gifttagging:Using pagging techniques - V

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Using pagging techniques - V

Leave a Reply