`

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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics