Pagination in java
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   k_k
Posted On:   Wednesday, September 26, 2007 01:52 PM

Hi All,
I wanna need help for pagiantion ...
i have result in list and want tht at one time only 5 results are show and need both next and previous button ....
thanks in advace

keshav

Re: Pagination in java

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, October 8, 2007 08:12 PM

or just use the "displaytag" taglib, or "eXtreme components" table taglib, both of which work great; the eXtreme table taglib is extendable and amenable to doing partial fetches from the database too. (both are Sourceforge projects, both also have their own .org web sites too)

Re: Pagination in java

Posted By:   Stephen_McConnell  
Posted On:   Wednesday, September 26, 2007 11:39 PM

Much of the details depend upon what type of application you are writing.... Is it a web ap... and applet, general application . . are you using JDBC or Hibernate or some other method of accessing the DB.... etc etc But an overview of the solution goes like this:


Most SQL dialects have a clause Limiting the number of rows returned from a query.


Postgresql uses a SELECT ..... LIMIT { count }


DB2 uses a FETCH FIRST n ROWS ONLY" in its SELECT statement.


You need to find what is the "Limiting" clause for your SQL dialect.


What one does is keep two key values in memory in the session object or whatever. The first one is the key of the first record in the recordset. The second is the key of the bottom record in the record set.


To page forward you issue a query selecting the next "n" records that are greater than the key at the bottom of the page.... (If the result set returns empty or less than the number you want, you have reached the end of file and you want to disable the NEXT button.)


To page backward you issue a query selecting the "previous" "n" records less than the key at the top of the page. (If your record set is empty, then you have reached the START of the file - and you want to disable the PREVIOUS button)


Once the result set is read in, you replace your top and bottom keys with the first and last records in the resultset.


This is a general idea. Coding it is half the fun. I seem to dimly remember this might have similar to the first question I answered on this forum YEARS and YEARS ago...

About | Sitemap | Contact