• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pagination logic in jsp

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Anybody has readily available code for pagination logic using ajax/jquery at client side rendering pagination?


Any good light weight API for handling pagination in jsp?


Thanks,
Sai
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is unclear. First you ask about client-side mechanisms. Then server-side using JSP. Which is it?

But, in fact, pagination should not occur at either of these levels -- it should be handled by the database. See the JSP FAQ for more information on how to paginate long data properly.

There are jQuery plugins that will help you with this, but this is not the appropriate forum to discuss them.
 
Praveen Kumar Singh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi saikrishna,

i recently implemented pagination in my project. be frank, it is not one page solution.
I can share idea with you, try to implement in your code

pagination based on these variables TotalNoOfPage,noOfRow and pageCount ;

1) TotalNoOfPage : Do the query in database using count(*) to find out how many rows are possible
2) noOfRow : rows to display in a single page.
3) pageCount : request page no.

Working Logic :
lets assume noOfRow = 25, so in first page display 25 rows by limiting now of rows from query (use LIMIT or equivalent keyword in sql )

at bottom logic to provide nos is bit complex, count no of pages by (noOfRow /noOfRow ), run for loop to display numbers,provide href with pageno at bottom
lets say 1(pageCount =1) ,2(pageCount =2) .....................5(pageCount =5) .............10(pageCount =10)
let say user click on link 5
in back end you got the pageCount value as 5, now you now that you have to fetch rows from 100 - 125
display same
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point being, you shouldn't ever grab more data from the database than you will display on the page. Why grab 10,000 rows of data, only to have the presentation layer pick 10 of them to show?
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I agree with your answers, but I feel that hitting database for each 100 records is also a costly process.
I google for pagination and found display tags third party API, don't know in what way it is functioning internally. It seems like it is getting all the available records from database and displaying in the browser

Is there any thrid party API which functions as per your explanation, like fetching only 100 or 1000 records per page each time?



Thanks again.
Sai
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any database access is a relatively costly process. But grabbing more data than you need is more costly than just grabbing what you need.

If your application is such that you are sure and have proved that people will always look at the next "page" of data, you might want to do some measure of pre-fetch and caching -- but that's the type of thing you should only do after determining that it will be helpful. Anything else is premature.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I got you. But is there any third party API which support this functionality?

Any comment on display tags. I am just going through display tags API now for implementing it in my project. Is there any other good API than display tags?


Thanks,
Sai

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None that I've used -- I find them all too over-complicated for something that's really a rather simple thing.
 
Praveen Kumar Singh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as i mention, pagination need significant amount of gui and database logic.
3rd party api can't handle both together.

some modern framework provide this feature. like JSF
please let me know the framework you are using in your app.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Praveen,,

This is simple MVC arch app using jsp,servlet,bean,dao etc.

I dont have idea on JSF. do you think Jquery can handle this pagination functionality?


Thanks,
Sai
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Kumar Singh wrote:as i mention, pagination need significant amount of gui and database logic.

Nonsense. Only if you over-complicate it.

As I already mentioned, jQuery has stuff that will help you out if you like.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!