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

来源:互联网 发布:阿里云域名绑定服务器 编辑:程序博客网 时间:2024/05/17 01:28

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中取出显示。

实例:

代码


Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><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>

原创粉丝点击