You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stanley Santiago <st...@netscape.com> on 2000/08/30 00:17:35 UTC

Example of struts:iterate ?

I looked up struts:iterate in the Struts Tag Lib docs but was unable to
grasp the usage of this tag.

Could someone point me to an example of this tag that iterates thru an
ArrayList object; each member
of the array is of String type. The output should be the members of the
ArrayList object

TIA,
Stan








Re: Example of struts:iterate ?

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Stanley Santiago wrote:

> I looked up struts:iterate in the Struts Tag Lib docs but was unable to
> grasp the usage of this tag.
>
> Could someone point me to an example of this tag that iterates thru an
> ArrayList object; each member
> of the array is of String type. The output should be the members of the
> ArrayList object
>

Assume your ArrayList full of Strings is available as a bean named "items",
and you want to list the contents of this array as an unordered list.  You
might do something like this:

    <ul>
    <struts:iterate id="item" name="items">
    <li><%= item %></li>
    </struts:iterate>
    </ul>

If the ArrayList was actually returned as the value of a bean property, it
would be slightly different.  For example, let's say you are doing a Chat
system that maintains a list of the user's favorite rooms, so the user
object has a getFavorites() method that returns an ArrayList (it works
equally well if the return value is a String array or an Iterator):

    <ul>
    <struts:iterate id="item" name="user" property="favorites">
    <li><%= item %></li>
    </ul>


> TIA,
> Stan

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat