Home  >  Article  >  php教程  >  Detailed explanation of the use of s:iterator tag in struts2

Detailed explanation of the use of s:iterator tag in struts2

高洛峰
高洛峰Original
2016-12-13 17:38:261462browse

Simple demo:
s:iterator tag has 3 attributes:
value: the collection to be iterated
id: the id of the element in the specified collection
status the index of the iterated element
1: jsp page definition element writing method array or list


A

The printed result is: 1A2A3A4A5A
2: Index usage
If status is specified, each iteration data has an instance of IteratorStatus, which has the following methods
int getCount( ) Returns how many elements are currently iterated
int getIndex() Returns the current element index
boolean isEven() Of course, whether the index is even Whether the index is odd


The current index is an odd number:

Current element value:

3: Traverse the map
value can be directly defined as:
value="#{"1":"a","2":"b"}"
each Elements are separated by good distances. The key and value between elements are separated by colons
value can also be the java.util.Map object in the data stack
The traversal is written as follows:

key :
value:

Of course both key and value can be used Use java's Object
3: Traverse the data stack. Simple List class,
List
class Attr{String attrName;String getAttrName(){return "123";}}



Of course value can also be written as value="%{label}" label can have .To operate the attribute List of
label, you can write it as value="%{label.list}", which is equivalent to: getLabel().getList();
4: Traverse 2 lists;
List attrN {color, size, style }
List attrV {red,20,gay}
The elements of these two lists are in one-to-one correspondence, one attrN corresponds to one attrV

index is :
attrName is : or
attrName is :




counter:



This tag is the main The function is to iterate out the collection. .
The value attribute indicates the value that needs to be displayed.

The status attribute is used to save some status values ​​during iteration.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn