1. value属性:可选的属性,value属性是指一个被迭代的集合,使用ognl表达式指定,如果为空的话默认就是ValueStack栈顶的集合.
2.id属性:可选属性, 是指集合元素的id
3.status属性:可选属性,该属性在迭代时会产生一个IteratorStatus对象,该对象可以判断当前元素的位置,包含了以下属性方法:
int getCount(); 迭代元素个数
int getIndex(); 迭代元素当前索引
boolean getFirst(); 是否为第一个
boolean getEven(); 是否为偶
boolean getLast(); 是否最后一个
bolean getOdd();
由于iteratorstatus对象并不是ognl的根对象因此访问需要加上 #访问如下例子:
<head>
<STYLE type="text/css">
.tr_even{
background-color: gray;
}
.tr_odd{
background-color: red;
}
</STYLE>
</head>
<body>
<s:set name="list" value="{'eeeee','ddddd','ccccc','bbbbb','aaaaa'}"></s:set>
<table border="1" cellspacing="0" bordercolor="red">
<tr>
<td>content</td>
<td>count</td>
<td>index</td>
<td>the first</td>
<td>ou shu</td>
<td>the last</td>
<td>ji shu</td>
</tr>
<s:iterator value="#list" var="o" status="s">
//实现奇、偶行不同颜色
<s:if test="#s.even">
<tr class="tr_even">
</s:if>
<s:else><tr class="tr_odd"></s:else>
<td>
<s:property value="#o"/>
</td>
<td>
<s:property value="#s.count"/>
</td>
<td>
<s:property value="#s.index"/>
</td>
<td>
<s:property value="#s.first"/>
</td>
<td>
<s:property value="#s.even"/>
</td>
<td>
<s:property value="#s.last"/>
</td>
<td>
<s:property value="#s.odd"/>
</td>
</tr>
</s:iterator>
</table>
</body>
</html>
#status.even是否为偶数
#status.odd 是否奇数行
#status.count 当前行数
#status.index 当前行的序号,从0开始[#status.count=#status.index+1]
#status.first 是否第一行
#status.last 是否最后一行
#status.modules(int) 当前行数取模