logic:Iterator标签(以下简称“该标签”)是Struts里非常常用的一个标签,其作用在于循环显示给定容器对象中的值。
如此常用的标签,其源代码当然需要拿出来研究一下,以下列举几条研究成果:
1、该标签内部使用Collection来表示给定的容器,所有的给定容器对象(如ArrayList,Map等)都会被其转化成为Collection,Collection实际就是Map和List的父类。
2、该标签自己维护循环索引,不用程序员管理索引
3、该标签常见的几个属性如下:name、property、scope、id
对应Struts给出的Api说明如下:
name:包括要遍历Collection的Jsp页面的bean的名字(如果property没有被定义),或者是那些通过getter方法获得属性的Jsp中的Bean的名字,这些getter方法返回的是Collection(如果property定义了)。
property:在name命名的Jsp bean中定义的属性的名字,通过getter方法返回一个Collection
scope:指示到哪里去寻找name为名字的bean,如果没有定义缺省为"any scope"
id:如果Collection非空的话,在每次遍历时候Collection中每个元素的名字。
其中除了id每个元素均为Rt expr,这儿的rt expr的意思就是Run Time Expression。明确的说就是,如果你对一个Attribute的<rtexprvalue>指定为true,你就可以在这样的属性中使用<%=%>之类的东东。这个配置文件在tld中。
只有id是必须要说明的。
关于Api说明的说明:
id只是一个临时标识,在下面的<bean:write里面出现的name属性要和id一致才能打印出<bean:write的property,而此property就是在iterator中的属性。
举例说明
以下代码生成一个阶梯状表格
系统 资源 操作
soft3
res3
opt3
soft12
res12
opt1211
soft11
res11
opt1111
在此之前传来一个request.getAttribute("userPurview"),所以有在第一个logic中的userPurview,就是在这个request里面寻找userPurview
返回的是一个list
<table width="300" border="0">
<tr><td>系统</td>
<td>资源</td>
<td>操作</td>
</tr>
<logic:iterate id="targetSys" name="userPurview" scope="request"> //这个id可以随便起名,但是要注意下文使用的一致性
<tr bgcolor="#cccccc"><td height="21" class="unnamed2">
<bean:write name="targetSys" property="cn"/> //此处name和上面id保持一致,property就是第一个list里面的元素
</td>
<td height="21" class="unnamed2"> </td>
<td height="21" class="unnamed3"> </td>
</tr>
<logic:iterate id="targetRes" name="targetSys" property="purviewResList">
<tr><td height="21" class="unnamed2"> </td><td height="21" class="unnamed5">
<bean:write name="targetRes" property="cn"/>
</td>
<td height="21" class="unnamed6"> </td>
</tr>
<logic:iterate id="targetOpr" name="targetRes" property="purviewOprList">
<tr><td height="21" class="unnamed4"> </td><td height="21" class="unnamed4"> </td>
<td height="21" class="redzi">
<bean:write property="cn" name="targetOpr"/></td>
</tr>
</logic:iterate>
</logic:iterate>
</logic:iterate>
</table>
结论:
多级迭代和单层差不多,唯一注意的就是id和<bean:write中的name的对应,上级logic的id与下级logic的name对应,并且取出来的要是个Collection,name和id不一定实际需要这个bean,都是虚拟的。
分享到:
相关推荐
在action里面写了方法获取一个list,再将这个list的值放到jsp页面中显示出来,用的是<s:iterator>标签。
struts2中iterator 标签的使用详解
NULL 博文链接:https://shupili141005.iteye.com/blog/667446
struts2中siterator 标签的使用详解 及 OGNL用法 struts2中siterator 标签的使用详解 及 OGNL用法
<s:iterator value="list" id="book" status="u"> <s:property value="id" /> <s:property value="name" /> <s:...
struts2 标签iterator使用我自己试过的
生成一个简单的iterator,并且使用iterator标签打印出内容。 <s:generator val="%{'aaa,bbb,ccc,ddd,eee'}"> <s:iterator> <s:property /> </s:iterator> </s:generator> 例2: 生成一个iterator,使用...
自己使用过的struts2标签总结 1. resList是action中的一个属性 <s:iterator id="rs" value="resList" status="count" > </s:iterator> <s:iterator id="pwd" value="#request.usePwdList" status="mIndex"> ...
包含 strust2 s:iterator 一些常用情况的总结 如 遍历数组、list、map 并且list又分2种情况,map又分4种情况等。
NULL 博文链接:https://takeme.iteye.com/blog/1663239
一个运用Extjs,Struts2, json,iterator技术构建的iterator_jsonDemo2。iterator_jsonDemo1的链接:http://download.csdn.net/detail/cafebar123/8816409 运用了Extjs,Struts2, json,iterator技术, 将数据从...
web开发struts2标签 <s:property></s:property> <s:iterator></s:iterator>
struts标签做的增删查改 s:iterator s:textfield s:select s:checkboxlist
struts2标签详解 Iterator
<%@ taglib uri="/struts-tags" prefix="s" %> 结合例子,重点掌握以下标签的用法 (1) <s:property> (2) <s:set> (3) <s:if> 、<s:elseif>、<s:else> (4) <s:iterator> (5) <s:include> (6) <s:form>、<s:hidden> (7...
NULL 博文链接:https://davyjones2010.iteye.com/blog/1876389
NULL 博文链接:https://takeme.iteye.com/blog/1663039
。。。
。。。
经过这个周的纠结 成功的将其改成功了 比原著改的地方是在 mysetting.h 的48行Manager::iterator it = settingManager.find(userName); 改为typename Manager::iterator it = settingManager.find(userName); 还有75...