• 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

How to scroll between resultsets...

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends,
I have an application which has a search mechanism similar to the search in google. Now when I enter the expression and click on the search button I need to get the first 10 results and then when i press the next button the next ten results should be displayed. Similarly when I press the previous button the previous 10 records should be shown.
I am planning to get the result set and then store them in a model class and put them in he arraylist and then retreive the results one by one keeping the lower limit and upper limit in the session.
when I showed this approach my Pl was not satisfied. He asked me to do it in another way. Is there any way where I can traverse the records in a better way.
Thanks in advance
shekar.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "...one by one"? If you're only going to display 10 at a time, you'll most likely need to make a trip to the server to get the next 10 (or previous 10). This is alot of overhead for simply scrolling through a list.
You might try to "mirror" the records with javascript, therefore, the client can "scroll" through the records freely, without incurring the extra trips to the server. In other words, store the results in the ArrayList, then on your page load, dump the contents of the ArrayList into a javascript Array. It may be tricky coding, but creating a "circular array" in javascript will let you dynamically display 10 records at a time, without requiring a trip to the server.
WS
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you may create a stored procedure, which give you 10 records one time.
It accepts a page-like paramter to retrieve data from database.
Dan
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by danny liu:
you may create a stored procedure, which give you 10 records one time.
It accepts a page-like paramter to retrieve data from database.
Dan



What if the number of rows change ?
:roll:
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:


What if the number of rows change ?
:roll:


that's always a problem when paging through data with multiple requests to the datastore.
One solution would be to retrieve all data once and use the JSTL c:forEach to scroll through them after storing the data in a List.
This might be impractical if the dataset is huge (if the data is pretty static I elect to cache it, killing the cache whenever the data changes on the datastore and rebuilding it using some triggering mechanism).
In cases of large sets of data that changes often, there's no getting around the problem you describe.
The user will just see a slightly different dataset from the expected one if a record was inserted or deleted that caused the number or rows before the current row to change.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the grid tag.
http://www.dotjonline.com/main/index.jsp?url=/taglib/grid/grid.jsp
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic