English Title:(Turn) of label of the Iterator in Struts2 relevant use
在说明s:iterator标签的使用前,先了解下struts2中的Value Stack。这里参考了webwork中对Value Stack的描述,由于struts2是在webwork的基础上进行升级的,因此webwork对于Value Stack的表述同样适用于struts2。在这里不描述Value Stack具体做什么,但有两点需要注意: 一个value stack本质上是一个List; [0] --- 返回 [model,action,others]; 1) 、访问 days defined List<String> days ["Monday","Thursday","Friday","Sunday"] view plaincopy to clipboardprint? 2) 、使用 top 关键字使用(过滤掉Monday) defined List<String> days ["Monday","Thursday","Friday","Sunday"] view plaincopy to clipboardprint? top 指代当前迭代元素,可以为对象; 3)、使用 last / first 关键字使用 defined String[][] aTs = { { "一", "二", "三", "四" },{ "一一", "二二", "三三", "四四"} }; view plaincopy to clipboardprint?
下面的例子要实现每行输出颜色不同的效果。 defined List<String> days ["Monday","Thursday","Friday","Sunday"] view plaincopy to clipboardprint? odd关键字用来判断当前迭代位置是否为奇数行。odd返回boolean类型; even : boolean - 如果当前迭代位置是偶数返回true 假定countries是一个List对象,每一个country有一个name属性和一个citys List对象,并且每一个city也有一个name属性 。那么我们想要在迭代cities是访问countries的name属性就的用如下方式:
这里的 <ww:property value="name"/>取的是ctiy.name;<ww:property value="[1].name"/>取得是country.name 本文来自CSDN博客,转载请标明出处: (责任编辑:admin) |
Showing S:iBefore the use of Terator label, understand the Value Stack in next Struts2 first. Consulted be opposite in Webwork here the description of Value Stack, because Struts2 undertakes upgrading on the foundation of Webwork, because of this Webwork to Value Stack state apply to Struts2 likewise. Do not describe Value Stack here specific what to do, but have needed to notice at 2 o'clock: A Value Stack is a List substantially; [0]---Return [Model, action, others] ; Days of 1) , visit Defined List<String> Days ["Monday" , "Thursday" , "Friday" , "Sunday" ] View Plaincopy To Clipboardprint? Key word of 2) , use Top is used (filter Monday) Defined List<String> Days ["Monday" , "Thursday" , "Friday" , "Sunday" ] View Plaincopy To Clipboardprint? Top points to element of acting current iteration, can be an object; Key word of 3) , use Last / First is used Defined One " of String[][] ATs = {{" , "2 " , "3 " , "4 " } , {" one by one " , "22 " , "33 " , "44 "} }; View Plaincopy To Clipboardprint? The Status attribute in Iterator label represents the position of current iteration; The example below should achieve the result with every output different color. Defined List<String> Days ["Monday" , "Thursday" , "Friday" , "Sunday" ] View Plaincopy To Clipboardprint? Odd key word uses judgement whether is current iteration position odd travel. Odd returns Boolean type;Evne key word uses judgement whether does current iteration position go for even number. Even returns Boolean type Even: If Boolean - is current iteration position is even number returns TrueOdd: If Boolean - is current iteration position is odd return TrueCount: The computation that Int - returns current iteration position (from 1 begin)Index: The number that Int - returns current iteration position (from 0 begin)First: If Boolean - is current iteration position is the first when return TrueLast: If Boolean - is current iteration position is last when return TrueModulus(operand: Int) : Int - returns current count (from 1 begin) with the modulus that appoints operand Assume Countries is object of a List, each Country has attribute of a Name and boy or girl friend of a Citys List, and each City also has property of a Name. So we want to be in the Name attribute that iteration Cities is visit Countries with following means: View Plaincopy To Clipboardprint? The <ww:p hereWhat Roperty Value="name"/> takes is Ctiy.name;<ww:pRoperty Value="[1].name"/> is obtained is Country.name The article comes from CSDN rich guest, reprint indicate please provenance: (Responsibility edits: Admin) |