view raw
Tone Tone - 10 months ago 67
Java Question

Struts logic:iterate

I'm using struts

and I need to change the style on the last row that it writes out.

I have a
, and
on the iterate tag, but I can't figure out a logic combination to say if
bean:size = indexId
because size is the size of the collection, and the max
is always going to size -1 because of starting at 0.


My last time I did Struts was early this year, so let me explain with best knowledge,

There is no way of determining the length of the collections by using logic:iterate (See explanation here). What you will have to do is the following:

Assuming your collections is placed under request.setAttribute("collections", allMyCollections);

You can use EL (Expression Language) to determine the size and determine if they are equal by using c:if, i.e. in this effect:

<logic:iterate name="collections" id="curElement">
    <c:if test="${curElement.indexId == ${fn:length(collections) - 1}}">
        <!-- It is pretty messy ...but you get the idea -->
        <!-- We are the last element...whoohoo!!! -->

Otherwise, use <bean:size /> to get the size of the collections, set it to a variable and you'll use scriplets to get the stored collections size and use <logic:equal> tags to see if the last index is at collections.size() -1 (but that's cumbersome).

Hope this helps.

PS The code is rough....