Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

RE: s2 newbie tag question: indexing specific elements of arrayList

jonathan lister

2007-02-13

Replies:

> I wondered what is the struts tag equivalent of this JSTL to retrieve
> the first element from an arrayList:
>
> <%@(protected)" %>
> <c:set var="thisCountry" value="${regionList[0].countryCode}"
> scope="page" />
> <c:set var="lastCountry" value="${regionList[0].countryCode}"
> scope="page" />
>
> Where regionList is of type ArrayList<RegionBean>
>
> Looking at the online guides I guessed at
> <%@(protected)"%>
> <s:set id="thisCountry" name="regionList(0).name" scope="page"/>
> or
> <s:set id="lastCountry" name="regionList(%{0}).name" scope="page" />
>
> But these don't seem to work.
> I'm happy that regionList is in scope and not null because an iterator
> like this works OK
>   <s:iterator value="regionList">
>     <tr>
>      <td>
>       <s:property value="countryCode"/>
>      </td>
>      <td>
>         <s:property value="regionName"/>
>      </td>
>     </tr>
>   </s:iterator>
>
> (the JSTL code I'm converting inserts a spacer row in the table when
> the countryCode changes, hence the need to initialise before starting
> the iterator)
>
> Apologies if I missed something obvious ;-)
>
©2008 junlu.com - Jax Systems, LLC, U.S.A.