You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pierre Thibaudeau <pi...@gmail.com> on 2008/06/15 04:26:06 UTC

[S2] using for a sequence of integers

Is there a simple syntax with <s:iterator> or <s:generator> for displaying a
sequence of integers from 0 to N-1 ?
(The value of N is not known at compile time.)

At the moment, the only way I can think of doing this is not very appealing:
Within the action, create an ArrayList and populate it with the sequence of
integers.  Then iterate over that list with <s:iterator>.

Is there an easier way?  Something that would not involve the action?

Re: (!) Simple for-next loops using , was: Re: [S2] using for a sequence of integers

Posted by Dave Newton <ne...@yahoo.com>.
Aww, you guys are making me sad :(


--- On Tue, 6/17/08, Al Sutton <al...@alsutton.com> wrote:

> From: Al Sutton <al...@alsutton.com>
> Subject: Re: (!) Simple for-next loops using <s:iterator...>, was: Re: [S2] using <s:iterator> for a sequence of integers
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Tuesday, June 17, 2008, 9:43 AM
> +100 for the for tag.
> 
> It'll mean I don't end up using displaytag and
> including the jar just to 
> show simple paged lists.
> 
> Musachy Barroso wrote:
> > Nice, and confusing :)
> >
> > //I think we should create a "for" tag
> >
> > musachy
> >
> > On Tue, Jun 17, 2008 at 9:38 AM, Dave Newton
> <ne...@yahoo.com> wrote:
> >   
> >> From time to time people ask about implementing a
> simple loop using <s:iterator...> similar to
> <c:forEach begin="..."
> end="...">.
> >>
> >> Turns out there's some OGNL magic for doing
> simple loops (start at 0, go to n-1), and the significance
> of it never really struck me until the #this questions.
> >>
> >> <s:iterator value="(10).{ #this
> }">
> >>  Narnar
> >> </s:iterator>
> >>
> >> Aww yeah.
> >>
> >> Dave "OGNL FTW" Newton
> >>
> >> --- On Sat, 6/14/08, Pierre Thibaudeau
> <pi...@gmail.com> wrote:
> >>
> >>     
> >>> From: Pierre Thibaudeau
> <pi...@gmail.com>
> >>> Subject: [S2] using <s:iterator> for a
> sequence of integers
> >>> To: "Struts Users Mailing List"
> <us...@struts.apache.org>
> >>> Date: Saturday, June 14, 2008, 10:26 PM
> >>> Is there a simple syntax with
> <s:iterator> or
> >>> <s:generator> for displaying a
> >>> sequence of integers from 0 to N-1 ?
> >>> (The value of N is not known at compile time.)
> >>>
> >>> At the moment, the only way I can think of
> doing this is
> >>> not very appealing:
> >>> Within the action, create an ArrayList and
> populate it with
> >>> the sequence of
> >>> integers.  Then iterate over that list with
> >>> <s:iterator>.
> >>>
> >>> Is there an easier way?  Something that would
> not involve
> >>> the action?
> >>>       
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail:
> user-help@struts.apache.org
> >>
> >>
> >>     
> >
> >
> >
> >   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: (!) Simple for-next loops using , was: Re: [S2] using for a sequence of integers

Posted by Al Sutton <al...@alsutton.com>.
+100 for the for tag.

It'll mean I don't end up using displaytag and including the jar just to 
show simple paged lists.

Musachy Barroso wrote:
> Nice, and confusing :)
>
> //I think we should create a "for" tag
>
> musachy
>
> On Tue, Jun 17, 2008 at 9:38 AM, Dave Newton <ne...@yahoo.com> wrote:
>   
>> From time to time people ask about implementing a simple loop using <s:iterator...> similar to <c:forEach begin="..." end="...">.
>>
>> Turns out there's some OGNL magic for doing simple loops (start at 0, go to n-1), and the significance of it never really struck me until the #this questions.
>>
>> <s:iterator value="(10).{ #this }">
>>  Narnar
>> </s:iterator>
>>
>> Aww yeah.
>>
>> Dave "OGNL FTW" Newton
>>
>> --- On Sat, 6/14/08, Pierre Thibaudeau <pi...@gmail.com> wrote:
>>
>>     
>>> From: Pierre Thibaudeau <pi...@gmail.com>
>>> Subject: [S2] using <s:iterator> for a sequence of integers
>>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>>> Date: Saturday, June 14, 2008, 10:26 PM
>>> Is there a simple syntax with <s:iterator> or
>>> <s:generator> for displaying a
>>> sequence of integers from 0 to N-1 ?
>>> (The value of N is not known at compile time.)
>>>
>>> At the moment, the only way I can think of doing this is
>>> not very appealing:
>>> Within the action, create an ArrayList and populate it with
>>> the sequence of
>>> integers.  Then iterate over that list with
>>> <s:iterator>.
>>>
>>> Is there an easier way?  Something that would not involve
>>> the action?
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>     
>
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: (!) Simple for-next loops using , was: Re: [S2] using for a sequence of integers

Posted by Musachy Barroso <mu...@gmail.com>.
Nice, and confusing :)

//I think we should create a "for" tag

musachy

On Tue, Jun 17, 2008 at 9:38 AM, Dave Newton <ne...@yahoo.com> wrote:
> From time to time people ask about implementing a simple loop using <s:iterator...> similar to <c:forEach begin="..." end="...">.
>
> Turns out there's some OGNL magic for doing simple loops (start at 0, go to n-1), and the significance of it never really struck me until the #this questions.
>
> <s:iterator value="(10).{ #this }">
>  Narnar
> </s:iterator>
>
> Aww yeah.
>
> Dave "OGNL FTW" Newton
>
> --- On Sat, 6/14/08, Pierre Thibaudeau <pi...@gmail.com> wrote:
>
>> From: Pierre Thibaudeau <pi...@gmail.com>
>> Subject: [S2] using <s:iterator> for a sequence of integers
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Date: Saturday, June 14, 2008, 10:26 PM
>> Is there a simple syntax with <s:iterator> or
>> <s:generator> for displaying a
>> sequence of integers from 0 to N-1 ?
>> (The value of N is not known at compile time.)
>>
>> At the moment, the only way I can think of doing this is
>> not very appealing:
>> Within the action, create an ArrayList and populate it with
>> the sequence of
>> integers.  Then iterate over that list with
>> <s:iterator>.
>>
>> Is there an easier way?  Something that would not involve
>> the action?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] using for a sequence of integers

Posted by Pierre Thibaudeau <pi...@gmail.com>.
Good point.  Thank you!

2008/6/14 Dave Newton <ne...@yahoo.com>:

> I usually just use <c:forEach...> which has clean support for for/next type
> iteration. <s:iterator...> doesn't currently implement similar usage, AFAIK.
>

Re: (!) Simple for-next loops using , was: Re: [S2] using for a sequence of integers

Posted by Dave Newton <ne...@yahoo.com>.
I added a code sample to IteratorComponent and threw it in to <s:iterator...> tag docs but it'll take the normal amount of time to percolate.

(People complain about OGNL, but I sure do like it more than JSP EL, even with the occasional "Hmm, that's... interesting.")

Thanks for throwing it into the FAQ; not sure why I didn't :/

Dave

--- On Tue, 6/17/08, Laurie Harper <la...@holoweb.net> wrote:
> Thank you Dave; I've been telling myself there *must* be
> an OGNL solution for this for so long, but hadn't managed to
> track it down. It's the first time I've seen this solution 
> posted, and I definately think it's worth an entry in the FAQ!
> 
> http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=88506
> 
> L.
> 
> Dave Newton wrote:
> > From time to time people ask about implementing a
> simple loop using <s:iterator...> similar to
> <c:forEach begin="..."
> end="...">.
> > 
> > Turns out there's some OGNL magic for doing simple
> loops (start at 0, go to n-1), and the significance of it
> never really struck me until the #this questions.
> > 
> > <s:iterator value="(10).{ #this }">
> >   Narnar
> > </s:iterator>
> > 
> > Aww yeah.
> > 
> > Dave "OGNL FTW" Newton
> > 
> > --- On Sat, 6/14/08, Pierre Thibaudeau
> <pi...@gmail.com> wrote:
> > 
> >> From: Pierre Thibaudeau
> <pi...@gmail.com>
> >> Subject: [S2] using <s:iterator> for a
> sequence of integers
> >> To: "Struts Users Mailing List"
> <us...@struts.apache.org>
> >> Date: Saturday, June 14, 2008, 10:26 PM
> >> Is there a simple syntax with <s:iterator>
> or
> >> <s:generator> for displaying a
> >> sequence of integers from 0 to N-1 ?
> >> (The value of N is not known at compile time.)
> >>
> >> At the moment, the only way I can think of doing
> this is
> >> not very appealing:
> >> Within the action, create an ArrayList and
> populate it with
> >> the sequence of
> >> integers.  Then iterate over that list with
> >> <s:iterator>.
> >>
> >> Is there an easier way?  Something that would not
> involve
> >> the action?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: (!) Simple for-next loops using , was: Re: [S2] using for a sequence of integers

Posted by Laurie Harper <la...@holoweb.net>.
Thank you Dave; I've been telling myself there *must* be an OGNL 
solution for this for so long, but hadn't managed to track it down. It's 
the first time I've seen this solution posted, and I definately think 
it's worth an entry in the FAQ!

http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=88506

L.

Dave Newton wrote:
> From time to time people ask about implementing a simple loop using <s:iterator...> similar to <c:forEach begin="..." end="...">.
> 
> Turns out there's some OGNL magic for doing simple loops (start at 0, go to n-1), and the significance of it never really struck me until the #this questions.
> 
> <s:iterator value="(10).{ #this }">
>   Narnar
> </s:iterator>
> 
> Aww yeah.
> 
> Dave "OGNL FTW" Newton
> 
> --- On Sat, 6/14/08, Pierre Thibaudeau <pi...@gmail.com> wrote:
> 
>> From: Pierre Thibaudeau <pi...@gmail.com>
>> Subject: [S2] using <s:iterator> for a sequence of integers
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Date: Saturday, June 14, 2008, 10:26 PM
>> Is there a simple syntax with <s:iterator> or
>> <s:generator> for displaying a
>> sequence of integers from 0 to N-1 ?
>> (The value of N is not known at compile time.)
>>
>> At the moment, the only way I can think of doing this is
>> not very appealing:
>> Within the action, create an ArrayList and populate it with
>> the sequence of
>> integers.  Then iterate over that list with
>> <s:iterator>.
>>
>> Is there an easier way?  Something that would not involve
>> the action?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


(!) Simple for-next loops using , was: Re: [S2] using for a sequence of integers

Posted by Dave Newton <ne...@yahoo.com>.
>From time to time people ask about implementing a simple loop using <s:iterator...> similar to <c:forEach begin="..." end="...">.

Turns out there's some OGNL magic for doing simple loops (start at 0, go to n-1), and the significance of it never really struck me until the #this questions.

<s:iterator value="(10).{ #this }">
  Narnar
</s:iterator>

Aww yeah.

Dave "OGNL FTW" Newton

--- On Sat, 6/14/08, Pierre Thibaudeau <pi...@gmail.com> wrote:

> From: Pierre Thibaudeau <pi...@gmail.com>
> Subject: [S2] using <s:iterator> for a sequence of integers
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Saturday, June 14, 2008, 10:26 PM
> Is there a simple syntax with <s:iterator> or
> <s:generator> for displaying a
> sequence of integers from 0 to N-1 ?
> (The value of N is not known at compile time.)
> 
> At the moment, the only way I can think of doing this is
> not very appealing:
> Within the action, create an ArrayList and populate it with
> the sequence of
> integers.  Then iterate over that list with
> <s:iterator>.
> 
> Is there an easier way?  Something that would not involve
> the action?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] using for a sequence of integers

Posted by Dave Newton <ne...@yahoo.com>.
I usually just use <c:forEach...> which has clean support for for/next type iteration. <s:iterator...> doesn't currently implement similar usage, AFAIK.

Dave

--- On Sat, 6/14/08, Pierre Thibaudeau <pi...@gmail.com> wrote:

> From: Pierre Thibaudeau <pi...@gmail.com>
> Subject: [S2] using <s:iterator> for a sequence of integers
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Saturday, June 14, 2008, 10:26 PM
> Is there a simple syntax with <s:iterator> or
> <s:generator> for displaying a
> sequence of integers from 0 to N-1 ?
> (The value of N is not known at compile time.)
> 
> At the moment, the only way I can think of doing this is
> not very appealing:
> Within the action, create an ArrayList and populate it with
> the sequence of
> integers.  Then iterate over that list with
> <s:iterator>.
> 
> Is there an easier way?  Something that would not involve
> the action?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org