http://www.vaannila.com/struts-2/struts-2-example/struts-2-iterator-tag-example1

Struts 2 Iterator Tag Example

In Stuts 2 the iterator tag is used to loop over a collection of objects. The iterator tag can iterate over any Collection, Map, Enumeration, Iterator, or array.
01.<table class="songTable">
02. <tr class="even">
03. <td><b>Title</b></td>
04. <td><b>Genre</b></td>
05. </tr>
06. <s:iterator value="songs" status="songStatus">
07. <tr
08. class="<s:if test="#songStatus.odd == true ">odd</s:if><s:else>even</s:else>">
09. <td><s:property value="title" /></td>
10. <td><s:property value="genre" /></td>
11. </tr>
12. </s:iterator>
13.</table>

We use the iterator tag to iterator over the collection of songs. Here the Song property is of type ArrayList. To know more about the iterator status we can create an instance of the IteratorStatus object by specifying a value to the status attribute of the iterator tag. The newly created instance will be placed in the ActionContext which can be refered using the the following OGNL expression #statusName.

The table show the different properties of the IteratorStatus object.
Name Return Type Description
index int zero-based index value.
count int index + 1
first boolean returns true if it is the first element
last boolean returns true if it is the last element
even boolean returns true if the count is an even number.
odd boolean returns true if the count is an odd number.
modulus int takes an int value and returns the modulus of count.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值