You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jo...@vaisala.com on 2007/02/13 19:37:46 UTC

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

> I wondered what is the struts tag equivalent of this JSTL to retrieve
> the first element from an arrayList:
> 
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
> <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
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <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 ;-)
> 

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

Posted by Laurie Harper <la...@holoweb.net>.
<s:set name="thisCountry" value="regionList(0).name" scope="page"/>

or maybe

<s:set name="thisCountry" value="regionList[0].name" scope="page"/>

At any rate, you need to use the 'value' attribute to specify the value :-)

L.

jonathan.lister@vaisala.com wrote:
>> I wondered what is the struts tag equivalent of this JSTL to retrieve
>> the first element from an arrayList:
>>
>> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
>> <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
>> <%@ taglib prefix="s" uri="/struts-tags"%>
>> <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 ;-)
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org