STRUTS2 's label------iterator detailed

Source: Internet
Author: User
Struts2 's s:iterator can traverse any array in the data stack, the collection and so on the following simple demo:
The S:iterator tag has 3 properties:
Value: The collection that is iterated
ID: The ID of the element within the specified collection
The index of the status Iteration element 1:jsp the page definition element array or list
< S:iterator value= "{' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 '}" id= ' number ' >
<s:property value= ' number '/>a
</s:iterator>
Printing result: 1a2a3a4a5a 2: Usage of index
If status is specified, each iteration of the data has an instance of Iteratorstatus, and it has the following methods
int GetCount () returns several elements of the current iteration
int GetIndex () returns the current element index
Boolean IsEven () of course the index is even
Boolean IsFirst () whether the first element is currently
Boolean islast ()
Boolean isodd () whether the current element index is odd < S:iterator value= "{' A ', ' B ', ' C '}" id= ' char ' status= ' st ' >
<s:if test= "#st. Even ">
The index is now an odd number: <s:property value= ' #st. Index '/>
</s:if>
Current element value: <s:property value= ' char '/>
</s:iterator>
3: Traverse Map
Value can be defined directly as: value= "#{" 1 ":" A "," 2 ":" B "}"
Each element is well separated. The key and the value colon are separated between elements
Value can also be a Java.util.Map object inside the data stack
The traversal is written as follows: < S:iterator value= "map" id= "id" status= "st" >
Key: <s:property value= ' key '/>
Value:<s:property vlaue= ' value '/>
</s:iterator>
Of course, both key and value can make Java Object 3: traverse the data stack. Simple List class,
List<attr>
Class Attr{string Attrname; String Getattrname () {return "123";}} < s:iterator value= "label" id= "id" >
<s:property value= "#id. Attrname"/>
</s:iterator>
Of course value can also be written value= "%{label}" label can have. Operation
The Label property list can be written as value= "%{label.list}" equivalent to: Getlabel (). GetList (); 4: Traversal of 2 lists;
List<attrname> attrn {Color,size,style}
List<attrvalue> ATTRV {Red,20,gay}
The 2 list elements are one by one corresponding, one attrn corresponds to a ATTRV < S:iterator value= "%{attrn}" id= "id" status= "status" >
Index is: <s:property value= ' Status.index '/>
Attrname is: <s:property value= ' id '/> or <s:property value= '%{id} '/>
Attrname is: <s:property value= '%{attrv[#status. index]} '/>
</s:iterator>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.