Here's how I implement it: As a rule, it is recommended that you create a filter class that filters data and contains information related to pagination for you. I am using something like this:
public abstract class Filter{ private int currentPageNo; private int currentStartPageNo; private int currentEndPageNo; private int elementsPerPage; private int pageNumberInNavigation; public abstract Query createCountQuery(); public abstract Query createQuery(); public void setCurrentPageNo(){
You can have special subclasses of filters (depending on what you want to get), and each subclass will implement its createCountQuery()
and createQuery()
.
You would put your Filter
in the Velocity
context, and you could get all the necessary information from this class.
When you set the current current pf page, you update all the information you need (i.e. currentStartPageNo, currentEndPageNo).
You can also use the refresh()
method to return the filter to its original state.
And, of course, you must save an instance of the same filter in the session (I mean a web framework such as Struts, Turbine, etc.) when the user goes to the search page to which Filter
belongs.
This is just a guide, an idea, this is not a fully written executable code, just an example to get you started.
I will also recommend you a jQuery plugin called jqGrid , which has pagination support (although you must have support for retrieving data) and much more cool stuff. You can use it to display your data in a grid. I use it with Velocity
without any problems. It has many very nice and useful features, such as a filter toolbar, editable cells, data transfer in JSON
, XML
, etc. Honestly, I donβt know if it has pagination as you need (I use it with only one page displayed in the navigation, and you cannot click on the page, just use the following prev buttons to navigate), but it has there may be support for that.