struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Newfield <>
Subject Re: OGNL Iterator/Array Expression Question
Date Tue, 15 Sep 2009 05:25:31 GMT
Aren't these two identical by definition:

%{periodModel.weeks.iterator.{? true }[0].startDate}

> based on example code provided in the OGNL guide to get the startDate from
> the first object in a returned array from the iterator.

weeks is a collection of some form for you to be able to get an iterator 
from it.
weeks.iterator is an Iterator in the java sense.
{? true} says test each member of the collection, and if true==true, 
include it in the resulting colSolection.  I'm dubious this even makes 
sense on an iterator instead of on the collection the iterator is 
iterating over.

> I would like to make the 0 dynamic based on the 'wno' property so that I
> could do something such as:
> <s:property value="periodModel.weeks.iterator.{? true }[wno].startDate"/> 
> where wno might be the value 0,1,2, etc...

Somehow you need to be able to get that value with ognl.  If it's from 
your action, it'll probably come from a property of the action, and it 
might have the name wno if your action has a getWno() method.  If it's 
determined in the jsp you'll probably <s:set /> it, then it'll be 
addressed as #wno (since it's not on the value stack, but stored in an 
associated hash based on it's name).  Assuming the former, then

%{periodModel.weeks[wno].startDate} should do what you want.

> But I do not know the correct syntax.  I was reviewed the OGNL guide and am
> still a little new using OGNL expressions.

It's terse, but then again, so is the language.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message