You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kevin Wade <kw...@mindspring.com> on 2007/09/21 17:38:51 UTC
[s2] generator & iterator tags
Greetings all. I am having difficulty crafting an struts 2 iterator
using the generator tag. I want to iterate over a set of string
values and then test against the current one in the loop. Something
like this:
<s:generator val="%{'wizards,dwarves,elves'}" separator=","
id="myAttr">
<s:iterator>
<s:set name="groupname" value="#attr.myAttr.next" ></s:set>
< want to test groupname here, etc... >
</s:iterator>
</s:generator>
This doesn't work since the use of #attr.myAttr.next actually
iterates the iterator (!) which means the iteration loop skips over
one of the values.
I guess what I'm looking for is the correct ognl expression to get
the current value of the iterator created by the generator. Any ideas?
Kevin
Re: [s2] generator & iterator tags
Posted by Kevin Wade <kw...@mindspring.com>.
Thanks for the reply.
I did indeed try to create an <s:iterator../> over an immediate list
of those strings, but I could never get it to work. I can get it to
work over numbers (i.e. <s:iterator status="stat" value="{1,2,3,4,5}"
>), but not strings. Probably user error. I'd love to see a
solution to that.
But your suggestion to use the id parameter w/in the generated
iterator does indeed work. I was attempting to use "id" w/in the
generator tag which does not. So, in the end, this works for me:
<s:generator val="%{'wizards,dwarves,elves'}" separator=",">
<s:iterator id="groupname">
groupname is: <s:property value="#groupname"/><br/>
</s:iterator>
</s:generator>
Thanks for your help.
Kevin
On Sep 21, 2007, at 11:58 AM, Dave Newton wrote:
> --- Kevin Wade <kw...@mindspring.com> wrote:
>> <s:generator val="%{'wizards,dwarves,elves'}"
>> separator=","
>> id="myAttr">
>> <s:iterator>
>> <s:set name="groupname"
> value="#attr.myAttr.next"/>
>> < want to test groupname here, etc... >
>> </s:iterator>
>> </s:generator>
>
> I'm not sure why you're using <s:generator.../> at all
> since you could <s:iterator.../> over an immediate
> list.
>
> <s:property/> will return the current iteration
> object. You should be able to use <s:iterator id="..."
> .../> to create a named object for the current
> iteration for use in comparisons, just like a
> non-generated iterator, but that's just theory at this
> point.
>
> d.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
Re: [s2] generator & iterator tags
Posted by Dave Newton <ne...@yahoo.com>.
--- Kevin Wade <kw...@mindspring.com> wrote:
> <s:generator val="%{'wizards,dwarves,elves'}"
> separator=","
> id="myAttr">
> <s:iterator>
> <s:set name="groupname"
value="#attr.myAttr.next"/>
> < want to test groupname here, etc... >
> </s:iterator>
> </s:generator>
I'm not sure why you're using <s:generator.../> at all
since you could <s:iterator.../> over an immediate
list.
<s:property/> will return the current iteration
object. You should be able to use <s:iterator id="..."
.../> to create a named object for the current
iteration for use in comparisons, just like a
non-generated iterator, but that's just theory at this
point.
d.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org