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 accesss to indexed variable in bean Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "accesss to indexed variable in bean" Watch "accesss to indexed variable in bean" New topic
Author

accesss to indexed variable in bean

J. Cartwright
Greenhorn

Joined: Sep 27, 2004
Posts: 16
Hello All,

I'm trying to use JSTL to access and indexed property on a bean.

The bean accessor looks like:

public List getRecord(int index) {
return((List)records.get(index));
}

and my JSP looks like this:

<c:forEach items="${requestScope.dataBean.record[0]}" var="record">
${record}<br>
</c:forEach>

However, this doesn't work, complaining that:

Unable to find a value for "record" in object of class "DataBean" using operator "."

Can anyone help me?

Thanks!

-- john
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

Hmm, not something I've ever tried to do, and the JSP 2.0 Specification doesn't have much to say on this re the expression language.

Myself, I've never much cared for indexed properties, so I've always used a slightly different pattern which is known to be EL-friendly.

Rather than an indexed property, I usually have a discrete property that returns an array (or List, or Map, or whatever collection) and use the array indexing mechanism on the returned collection.

For example:



which can be used in the EL as



In your example, it looks like each of your indexed properties is a List, so you could define an accessor such as:



and use it in your page as:


[ November 16, 2005: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accesss to indexed variable in bean
 
Similar Threads
Bad practise? JavaBean where setX() actually should be addX()?
Indexed Properties Help!!!
logic iterate tag for Float array
Struts 1 , Use an array to capture multiple parameters
can't get indexed form property to work.