struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: Iterate -- Logic Tag
Date Fri, 16 Mar 2001 18:03:57 GMT

while it's true that java iterators and enumerators don't provide an index when
you loop through them, how many times have you found yourself using a local
count variable that you increment inside the loop?  i've encountered it plenty.
i don't think it's an uncommon scenario.

recently, i've ended up using a solution similar to Michael's to keep a counter,
but this doesn't seem ideal to me.  if people are really adamant about keeping
the iterate tag as it is, maybe the alternative would to construct an
indexedIterate tag or something like that.  on the other hand, from looking at
the source code for the iterate tag, there's already a lengthCount attribute
that stores the number of iterations.  why not just expose that?


>  From:
> Date:   03/16/2001 10:55 AM
>raghu tadi <> wrote:
>> How do i get the Position value of a particular element in say a
>> Vector when i use the iterate tag.Sample snippet would be like,
>> <pre>
>> Vector v has some String elements..
>> for(int i =0 ; i < v.size(); i++)
>> {
>>    out.println(v.elementAt(i));
>> }
>> </pre>
>> Question is: How do i get the i-th element from Vector V when i use
>> the Iterate Tag..
>As Jean-Noel said, if you really want to get a particular element, you
>don't want to use iterate. But if what you are actually looking for is
>how to get the index of the current element inside an iterate block, I
>think you need to manage that separately. It's not ideal, but here's
>what I do to produce a table with alternately shaded rows:
>   <% int rowNumber = 0; %>
>   <logic:iterate id="ddItem" name="dropdownItems">
>     <% if( ( ++rowNumber % 2 ) == 1 ) { %>
>     <tr class="listViewOdd">
>     <% } else { %>
>     <tr class="listViewEven">
>     <% } %>
>       <td>...</td>
>       <td>...</td>
>       <td>...</td>
>     </tr>
>   </logic:iterate>
>It would be nice if interate also made an index available, but you can
>do something like that as a work-around for now (unless someone has a
>better suggestion).
>Michael Hackett
>Developer, Pictorius Inc.

View raw message