• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Complex structure in JSTL

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Marshal
Posts: 28296
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I want my playground back. Here, I'll give you this tiny ad for it:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic