Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display x rows of data with BACK/FORWARD buttons to navigate

Status
Not open for further replies.

dove85

MIS
Aug 8, 2001
19
0
0
US
Your help would be appreciated.

------------------------------------------------------------
QUESTION 1:

I need to display a list of vendor info in a tabular format (the data is
from an Oracle database). The list is rather long. Right now I have it
displayed on 1 page with scroll bars on the right/bottom.

I would like to know if it is possible to have the page display 10 records
at a time and with BACK and FORWARD buttons to navigate thru the records.

I can do it in JavaScript with the data "hard-coded" in arrays. But I need
to handle dynamic data here.

------------------------------------------------------------
QUESTION 2:

Is it possible to have a list of records displayed in a tabular format
(object items are read only) , highlight the selected record, and display
the selected record in a form format (object items are editable) on the
lower part of the same window?

Right now, I have the tabular info in one JSP, and each record has a readio
button. When a record is selected, another JSP kicks in and the editable
form replaces the tabular list (I would like to have them both in the same
window at the same time, and the bottom portion reflects whatever selection
made to the upper portion).

------------------------------------------------------------

Dove85
 
The answer to question one is yes. You could do this by check the size of your ResultSet and placing the appropriate next and/or previous buttons on the form. In the next page you could skip the first X number of records multipled by the current page number Y (where X is the amount per page). Thus you would need to pass to the page two parameters: The number of records per page and the current page number. This is pretty straight-forward when you still coding it. It is a bit inefficient since you will most likely be querying the DB each time and skipping records. You could also use some type of persistent storage (Session, EJB) to retain the query results between requests.

The answer to question two is also yes but I would recommend a NO. You could most definitely do this but it is going to require either client-side javascripts or Java Applets. Neither of which I am too thrilled with using on what could easily be a completely server-side process.

I hope I explained everything clearly enough. Just write back if you are confused on something or if you have additional questions. Wushutwist
 
Wushutwist,

Thanks. Your explanation is very clear.

I am interested in learning this "some type of persistent storage (Session, EJB) to retain the query results between requests". Could you elabrate?

Thank you again.
Dove85

 
Question 1:

This is what I would do. jsp query db when button clicked and display the info. Store the info(list of vendors) into session. Also in your jsp, create a constant (10 in this case) and add it to the session. Add a page no in the session too (value should be 1 because you just retrieve data from the db and want to display the first page). Have your back and forward buttons link to a new jsp(see below).

Create a jsp to cater to forward and backward. This jsp will purely be used to display forwards and backwards. The coding to display info would be same as the previous jsp. Using the values in the jsp, display the list of vendor using the pageno, the button clicked (whether +1 to pageno or -1), and the constant. The subsequent forward will be linked to this jsp too. ONLY when a new query to the database is made, will you call back the first jsp.

This should be quite simple, if you have any doubts, can ask me again.

Question 2:

I agree with Wushutwist. Javascript is not very friendly (sometimes can only work in a browser, either IE or netscape) and Applets doesn't really suit the requirements...

Leon
 
Thanks, wushutwist and Leon.

How do I store the ResultSet into session? I tried
<% session.setAttribute(vendorList, vendor); %>

where &quot;vendor&quot; is the ResultSet with type String[][], but session.setAttribute only takes type String.

Dove85
 
setAttribute takes a String for the name of the attribute and an Object.
Code:
<% session.setAttribute(&quot;vendorList&quot;, vendorList); %>
Then you can retrieve it by:
Code:
<% List vendorList = (List) session.getAttribute(&quot;vendorList&quot;); %>
Also don't store the actual ResultSet parse it out into a Collection and store that. In my example I assume you put it into some kind of List.
Wushutwist
 
Wushutwist,

I am a bit confused now.

I was trying to find a way to associate the ResultSet (which is &quot;vendor&quot; of type String[][]) with the session. I just picked the name &quot;vendorList&quot; randomly.

So, if I have a ResultSet named &quot;vendor&quot; of type String[][], how do I parse it out into a Collection and then retrieve it?

<%! String[][] vendor; %>
<% vendor = select.getVendor(); %> //got vendor list from Java Bean

Thanks.
Dove85

 
I am wondering which is a more efficient method.
1. Each time the prev or next button is clicked, it connects to the database and query the database, then only display the records for that page.

2. Save the entire ResultSet in a session object, so when prev or next is clicked, it doe not hit the database again.

The 2nd method avoids hitting the database to run the same query mutltiple times. But it may be bad for the memory if the ResultSet returns thousands of rows. Another problem is that session may time out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top