Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keep track of database row in jstl 'forEach' iteration

 
thomas silver
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64977
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Stefan Evans
Bartender
Posts: 1753
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic