This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Complex structure in JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Complex structure in JSTL" Watch "Complex structure in JSTL" New topic
Author

Complex structure in JSTL

Mike Higgins
Greenhorn

Joined: Mar 14, 2006
Posts: 1
Hello everyone,

I have a difficult question about JSTL.

I have following strutures in my WebApp but I don't know how to
reterieve data from it using JSTL.

So first, I have a container class for data. Code snippet is below.
It contains different objects stored by key value.

public class UserResponse extends Hashtable
{
public UserResponse(){
}

// Getter
public Object getResponse(String key) {
return get(key);
}
// Setter
public void setResponse(String key, Object value) {
put(key, value);
}
}

Then I have a ordinary SessionBean like this
public class SessionInfoBean implements java.io.Serializable
{
private String SessionID;
private String RowRecord;
private String RowNumber;
...
and I read them from database and store them into an ArrayList.
like this way:

ArrayList SessionsList = new ArrayList();
while (rs.next())
{
SessionInfoBean sessionInfoBean = new SessionInfoBean();
sessionInfoBean.setSessionID(rs.getString("sessionid"));
sessionInfoBean.setRowNumber(Long.toString(rs.getLong("row_number")));
sessionInfoBean.setRowRecord(rs.getString("rowrecord"));
SessionsList.add(sessionInfoBean);
}

Then I store the ArrayList of SessionInfoBean intems into UserResponse object that is descripted in the beginning this message. Code look like this:

userResponse.setResponse(Constants.DATA_BY_ID, (Object) SessionsList);

The question is: Can I iterate all properties that are in ArrayList stored into SessionInfoBean items using JSTL?

Is this too complex or can it be resolved?
I have tried almost everytging that comes into my mind but not succeeded.
Can anyone give some "light" how to solve this with JSTL?

Thanks!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You can certainly iterate through an ArrayList in JSTL, since it's a List. And if your SessionInfoBean is a "well-formed" JavaBean, then you can access it in JSTL with no problem. I don't understand where the UserResponse object comes into the picture, though. But JSTL can access it too, since it's a Map.

To iterate through a List in JSTL:where "sessionlist" is the name of a session, request, or page variable that contains the List. To access something from the SessionInfoBean you just use its JavaBean properties:for example. And to access a Map by its key in JSTL you do something like this:
Gene Winston
Greenhorn

Joined: Feb 13, 2006
Posts: 3
Thanks Paul for answering!

I'm doing a small MVC based stuff and in my previous example
following code is little difficult to understand, because it has a parameter.

Usually, or what books shows beans contains strings having
only getter and setter methods like getSpeed or setSpeed
and you just reference them easily using e.g. "speed"
without any parameters. But when a Bean's member is a Collection
with key and you should ask first the proper Collection item and then it's
object properties, that makes me feeling fuzzy. Especilly when trying to use
JSTL.

// Getter that can return a collection
public Object getResponse(String key) {
return get(key);
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60797
    
  65

Gene, I'm not sure exactly what your question is. Please elaborate. Also in the future, please open your own topics with your question rather than tacking it onto someone else's.

A few points. If a method takes a parameter, it's not a "getter" (the proper term is actually "accessor"), it's just a method that doesn't follow the JavaBean standard.

For use with the EL, your classes must adhere to the bean standards.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Complex structure in JSTL
 
Similar Threads
Accessing Object in a JSP using JSTL
Iterating over hashMap in facelets not working
Display ArrayList data on jsp page
Need a disconnected resultset
Pass By Value (again)