Structs中<logic:present><logic:iterator>的使用

logic是structs中的逻辑标签,类似于if/else的逻辑关系,可以通过使用这个标签改变页面布局。
present标签,在cope里(cope包括request,page,session,application)判断name对象的property属性是否存在,如果存在则执行present标签内部的代码。
iterate标签,在cope里判断name对象的property属性是否存在(name.property肯定是或最终转化为collection类型),如果存在则以id为键值循环将name.property的值存入pagecontext中。
iterate标签一般配合<bean:write>标签使用,此标签从pagecontext中以name(这个name要和iterate中的id一致)为键值从pagecontext中取出显示。

实例:


 

代码
<logic:present name="custInforForm" property="footer">//判断custInforForm.getFooter()是否有值,如果有值则执行标签内部的代码
 <logic:iterate name="custInforForm" id="customer" indexId="indexId"
  property
="footer.dataArray">//判断custInforForm.getFooter().getDataArray是否有值,如果有值则循环执行标签内部的代码
  <tr>
   
<td><input type="checkbox" name="cbSelect"
    value
="<bean:write name="customer" property="customerId"/>"></td>//这句的name要等于iterate标签内的id值,要以这个值到pagecontext里取值
   <td style="text-align: center;"><%=(indexId.intValue() + 1)%>
   
</td>
   
<td><a href="#"
    onclick
='toDisplay("<bean:write name="customer" property="customerId"/>")'>
   
<bean:write name="customer" property="customerId" /> </a></td>
   
<td><bean:write name="customer" property="customerName" /></td>
   
<td><param:display type="ci.assiManager1" name="customer"
    property
="customerManagerId" /></td>
   
<td><param:display type="ci.assiManager1" name="customer"
    property
="customerAssimanagerId" /></td>
   
<td><param:display type="ci.custDep1" name="customer"
    property
="customerManagerDep" /></td>
  
</tr>
 
</logic:iterate>
</logic:present>

总结:在structs标签中,一般情况下name表示引用一个变量,id表示建立一个变量

 参考:http://tech.ddvip.com/2008-12/122895891399042.html

原文地址:https://www.cnblogs.com/xryyforver/p/1803741.html