File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes keep track of database row in jstl 'forEach' iteration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "keep track of database row in jstl Watch "keep track of database row in jstl New topic
Author

keep track of database row in jstl 'forEach' iteration

thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
How could one keep track of the row (or a field in that row specifically) in the database in jstl 'forEach' iteration over the rows of database when a user licks on the image button on each row? Just to be clear, the 'index' property of 'varStatus' just keeps track of the row in the iterated collection, not in the database. For some reason, the editor did not let me post the codes here. Many thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

Not sure what you mean. By the time users are presented with an opportunity to click anything, the JSP has long seen finished executing.

Are you talking about how to identify which row's data the user clicks on after the JSP has been delivered and a subsequent submit is performed?
[ August 28, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by thomas silver:
...when a user licks on the image button on each row?


I'd hate to get that user's hand me down monitor. Ewe!


GenRocket - Experts at Building Test Data
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
My guess would be you are presenting an "index" of thumbnail images, and then you want the user to click on one, and see it in full detail?

Easiest way is to put a url on each image, with the id of the image in question as a parameter. Something like this (using JSP2.0)

thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
Bear, you were correct in your guess. Sorry that I wasn't clear enough. Yes, clicking on the image link(button) directs the user to another jsp page.

Greg, it was hot here so I was thinking for a full min but still didn't get your joke

Steffan, yes I followed a similar approach by using 'value' property instead of 'id' property.

I got things worked out by saving the value of 'varStatus' within the collection then pass the whole collection to the second jsp page in session scope. One thing I noticed though, is that if a field is CLOB or BLOB, its contents won't be retrievable at all from session variable. The error message complained of a failed database connection. It seems as though jstl <c:set .... scope="session"> only passes the references to the CLOB/BLOB objects, not the actually objects. For example, in a scriptlet in the forwarded jsp, I was able to print out the Clob object (after retrieve it from session variable and typecasting it to Clob- (something like oracle.sql.CLOB@7634gadfa6) but if I tried to print out object.length(), I got that error message. I now have to resort to open another database connection in a scriptlet (instead from jstl <sql:setDatasource ...> tag), then use the getClob(). Any other alternative? Thank you all for the help.
[ August 29, 2006: Message edited by: thomas silver ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Database access and binary file manipulation from a JSP is never a good idea.
The accepted 'best practice' these days is to write Java objects that deal with the database and return the results as arrays or collection objects.
Call these objects from servlets and then pass the results to a JSP for formatting.

Even the JSTL spec states that the JSTL/SQL tags were not meant for anything other than prototyping or trivial apps.
In my opinion, they never should have been written.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Consider Paul's rocket mass heater.
 
subject: keep track of database row in jstl 'forEach' iteration
 
Similar Threads
About the custom tags and custom tag library..
c:forToken ? or c:forEachToken ?
Array Iteration in JSP
How to Print Serial number on jsp?
HashSet in forEach tag