struts tag iterator高级用法


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.

如果指定了status,每次的迭代数据都有IteratorStatus的实例,它有以下几个方法
int getCount()返回当前迭代了几个元素
int getIndex()返回当前元素索引
boolean isEven()当然的索引是否偶数
boolean isFirst()当前是否第一个元素
boolean isLast()
boolean isOdd()当前元素索引是否奇数



<s:iterator value="groupDao.groups" status="groupStatus">
<tr class="<s:if test="#groupStatus.odd == true ">odd</s:if><s:else>even</s:else>">
<td><s:property value="name" /></td>
<td><s:property value="description" /></td>
<td>
<s:iterator value="users" status="userStatus">
<s:property value="fullName" /><s:if test="!#userStatus.last">,</s:if>
</s:iterator>
</td>
</tr>
</s:iterator>



<s:bean name="org.apache.struts2.example.IteratorExample" id="it">
<s:param name="day" value="'foo'"/>
<s:param name="day" value="'bar'"/>
</s:bean>
<p/>
<table border="0" cellspacing="0" cellpadding="1">
<tr>
<th>Days of the week</th>
</tr>
<p/>
<s:iterator value="#it.days" status="rowstatus">
<tr>
<s:if test="#rowstatus.odd == true">
<td style="background: grey"><s:property/></td>
</s:if>
<s:else>
<td><s:property/></td>
</s:else>
</tr>
</s:iterator>
</table>




<s:action name="entries" id="entries"/>
<s:iterator value="#entries.entries" >
<s:property value="name" />
<s:property />
<s:push value="...">
<s:action name="edit" id="edit" >
<s:param name="entry" value="[0]" />
</s:action>
</push>
</s:iterator>




<s:iterator status="stat" value="{1,2,3,4,5}" >
<!-- grab the index (start with 0 ... ) -->
<s:property value="#stat.index" />

<!-- grab the top of the stack which should be the -->
<!-- current iteration value (0, 1, ... 5) -->
<s:property value="top" />
</s:iterator>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值