This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to scroll between resultsets...  RSS feed

 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • 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.
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • 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
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • 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
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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:
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • 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.
 
Joe Pardi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the grid tag.
http://www.dotjonline.com/main/index.jsp?url=/taglib/grid/grid.jsp
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!