You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mannem, Taati" <Ta...@AIG.com> on 2002/05/18 00:41:28 UTC

Iterator Simple

Guys,
	When I iterate thru <logic:iterator> how do I know that I am in the
last element?
I have tried using some other way like getting the index and comparing but
it doesnt seem to work..
The reason why I want to do this

if I am in the last element I need to print something and if I am not then I
dont have to print.
Thanks in advance.

Regards,
Taati


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Iterator Simple

Posted by Ted Husted <hu...@apache.org>.
There is a bean:size tag that could help with this. 

But, it's possible that you might want to put any logic this complex
into the object as a helper method. The object you are iterating should
be able to tell you whether it is the last item or not and return that
as a simple value you can test. 

Placing helper method on objects to help with presentation issues is a
standard J2EE pattern, so don't be afraid to use it.

Though, in most cases, you can just write whatever it is after the
iterate completes, since it always ends after the last item. 

It may be that you want to present the markup one way when there is one
item, and another way when there is more than item. 

The bean:size tag can help with this, though personally I use helper
methods that tell me whether my result object is empty or not (and so
forth). The presentation page should be as dumb as possible, since there
is enough going on there already. 

-- Ted Husted, Husted dot Com, Fairport NY US
-- Developing Java Web Applications with Struts
-- Tel: +1 585 737-3463
-- Web: http://husted.com/about/services


"Mannem, Taati" wrote:
> 
> Guys,
>         When I iterate thru <logic:iterator> how do I know that I am in the
> last element?
> I have tried using some other way like getting the index and comparing but
> it doesnt seem to work..
> The reason why I want to do this
> 
> if I am in the last element I need to print something and if I am not then I
> dont have to print.
> Thanks in advance.
> 
> Regards,
> Taati
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Iterator Simple

Posted by Joseph Barefoot <jo...@hereuare.com>.
The tag does have an optional attribute called "indexId" whose value is the
name of a page scope bean to hold the index.  I think that this index bean
must be of type Integer (someone correct me if this is wrong), so you would
do a <bean:define> for the Integer bean with an appropriate name.  Then you
can reference the bean with <logic:equals> or <bean:write> tags within the
<logic:iterator> tag.  Or you can just use a scriplet. <<horrified gasps
from the peanut gallery>> :)

I'm assuming you could re-use the same index bean for different
<logic:iterator> tags as long as they are not nested inside one another..

> -----Original Message-----
> From: Mannem, Taati [mailto:Taati.Mannem@AIG.com]
> Sent: Friday, May 17, 2002 3:41 PM
> To: struts-user@jakarta.apache.org
> Subject: Iterator Simple
>
>
> Guys,
> 	When I iterate thru <logic:iterator> how do I know that I am in the
> last element?
> I have tried using some other way like getting the index and comparing but
> it doesnt seem to work..
> The reason why I want to do this
>
> if I am in the last element I need to print something and if I am
> not then I
> dont have to print.
> Thanks in advance.
>
> Regards,
> Taati
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>