• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pagination logic in jsp

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic