Usually you want your database to do the hard work of pagination and sorting. With MySQL, for example, you can get a results page sorted by date by adding
ORDER BY date ASC LIMIT 5,5
to the end of your SQL query. If you use hibernation, you can do this in a vendor-independent way using the API criteria:
List<MyDomainClass> results = (List<MyDomainClass>) getSession() .createCriteria(MyDomainClass.class) .setFirstResult(5) .setMaxResults(5) .addOrder(Order.asc("date")) .list();
To display paginated navigation, you also need to calculate the total number of results to find out how many pages there are:
int count = (int) getSession() .createCriteria(MyDomainClass.class) .setProjection(Projections.rowCount()) .list().get(0);
You can add restrictions for both searches, for example, if you want to filter out the last name you could add:
.add(Restrictions.eq("lastname", "Smith")
(This needs to be added to both the count query and the list query).
When you know the total number of results, the number of pages and the number of the current page, you can calculate the range of such results:
How you show navigation is up to you. Some platforms have standard components. Otherwise, you will have to think about how to handle a huge number of pages. A general approach is to show a range of, for example, 10 page numbers and a forward / reverse jump to start / go to end links.
Hope this helps.