You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ets04uga <et...@yahoo.com> on 2009/09/15 03:01:58 UTC
OGNL Iterator/Array Expression Question
I have the following code:
<s:property value="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.
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...
But I do not know the correct syntax. I was reviewed the OGNL guide and am
still a little new using OGNL expressions.
Can someone offer some guidance?
Thanks,
Eric
--
View this message in context: http://www.nabble.com/OGNL-Iterator-Array-Expression-Question-tp25446210p25446210.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: OGNL Iterator/Array Expression Question
Posted by Dale Newfield <da...@newfield.org>.
Aren't these two identical by definition:
%{periodModel.weeks.iterator.{? true }[0].startDate}
%{periodModel.weeks[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.
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org