Is there any way to apply break from a <s:iterator> tag.

View: New views
6 Messages — Rating Filter:   Alert me  

Is there any way to apply break from a <s:iterator> tag.

by Muthu Velappan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

 

I have a 1000 items in a collection and iterating it through <s:iterator >
tag. At certain point of time, I would like to break from the loop with out
proceeding further items. Is there any way to do this in struts tags itself
or should I use JSTL?

 

Regards,

Muthu

 


Re: Is there any way to apply break from a <s:iterator> tag.

by DNewfield :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Muthu Velappan wrote:
> I have a 1000 items in a collection and iterating it through <s:iterator >
> tag. At certain point of time, I would like to break from the loop with out
> proceeding further items. Is there any way to do this in struts tags itself
> or should I use JSTL?

This isn't quite what you asked for, but besides loading the rest of the
1000 items (which I'm guessing are already in memory anyway?), I think
this is about all you can do with ognl:

<s:set var="abortLoop" value="%{false}"/>
<s:iterator>
   <s:if test="%{!#abortLoop}">
     ...
     ...
     maybe <s:set var="abortLoop" value="%{true}"/>
   </s:if>
</s:iterator>


-Dale

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


Re: Is there any way to apply break from a <s:iterator> tag.

by Paweł Wielgus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
as [1] states:
"The begin, end and step attributes are only available from 2.1.7 on"
so if You are using 2.1.8 you can iterate over only a subset.

[1] - http://struts.apache.org/2.x/docs/iterator.html

Best greetings,
Paweł Wielgus.


2009/11/5 Dale Newfield <dale@...>:

> Muthu Velappan wrote:
>>
>> I have a 1000 items in a collection and iterating it through <s:iterator >
>> tag. At certain point of time, I would like to break from the loop with
>> out
>> proceeding further items. Is there any way to do this in struts tags
>> itself
>> or should I use JSTL?
>
> This isn't quite what you asked for, but besides loading the rest of the
> 1000 items (which I'm guessing are already in memory anyway?), I think this
> is about all you can do with ognl:
>
> <s:set var="abortLoop" value="%{false}"/>
> <s:iterator>
>  <s:if test="%{!#abortLoop}">
>    ...
>    ...
>    maybe <s:set var="abortLoop" value="%{true}"/>
>  </s:if>
> </s:iterator>
>
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

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


Re: Is there any way to apply break from a <s:iterator> tag.

by DNewfield :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Muthu Velappan wrote:
> I have a 1000 items in a collection and iterating it through <s:iterator >
> tag. At certain point of time, I would like to break from the loop with out
> proceeding further items. Is there any way to do this in struts tags itself
> or should I use JSTL?

If you're so inclined, it would probably be pretty easy to add this
functionality to the iterator tag, and I would guess that a patch with
that functionality would probably be accepted fairly quickly (just add
it to a JIRA ticket).  My first guess would be to add an attribute like
"break" that gets evaluated each time through the loop, potentially
terminating the iterator early (corner condition--make sure that it can
abort correctly even before the first time through the loop body).

-Dale

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


RE: Is there any way to apply break from a <s:iterator> tag.

by Muthu Velappan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I added a JIRA ticket for this and here is the URL for future tracking.
https://issues.apache.org/struts/browse/WW-3317 

Let me try to get this enhancement done and update the patch there in next
couple of weeks. Thanks for your thoughts anyway.

~Muthu

-----Original Message-----
From: Dale Newfield [mailto:dale@...]
Sent: Thursday, November 05, 2009 10:09 PM
To: Struts Users Mailing List
Subject: Re: Is there any way to apply break from a <s:iterator> tag.

Muthu Velappan wrote:
> I have a 1000 items in a collection and iterating it through <s:iterator >
> tag. At certain point of time, I would like to break from the loop with
out
> proceeding further items. Is there any way to do this in struts tags
itself
> or should I use JSTL?

If you're so inclined, it would probably be pretty easy to add this
functionality to the iterator tag, and I would guess that a patch with
that functionality would probably be accepted fairly quickly (just add
it to a JIRA ticket).  My first guess would be to add an attribute like
"break" that gets evaluated each time through the loop, potentially
terminating the iterator early (corner condition--make sure that it can
abort correctly even before the first time through the loop body).

-Dale

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




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


Re: Is there any way to apply break from a <s:iterator> tag.

by RogerV :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


DNewfield wrote:
<s:set var="abortLoop" value="%{false}"/>
<s:iterator>
   <s:if test="%{!#abortLoop}">
     ...
     ...
     maybe <s:set var="abortLoop" value="%{true}"/>
   </s:if>
</s:iterator>
I look forward to the implementation of the "maybe" command - I know that I'll find it useful and I don't think even InterCal has this feature :)

Regards