Home > php教程 > PHP开发 > body text

Usage of s:iterator

高洛峰
Release: 2016-12-13 17:31:24
Original
1310 people have browsed it

struts2’s s:iterator can traverse any array, collection, etc. in the data stack. Here are some simple demos:
s:iterator tag has 3 attributes:
value: the iterated collection
id: the element in the specified collection The id
status is the index of the iterated element

1:jsp page definition element writing array or list



A

The printed result is: 1A2A3A4A5A

2: Index usage
If specified status, each iteration data has an instance of IteratorStatus, which has the following methods

1: #status.odd Whether the current element index is an odd number of rows

2: # status.even Is the current element index even?
Line

3: #status.count How many elements are currently iterated
4: #status.index Current element index, starting from 0『#status.count=#status.index+1 』

5: #status.first Whether the current element is the first
6: #status.last Whether the current element is the last
7: #status.modules(int) Modulo the number of current rows



  Current index It is an odd number:

Current element value:

3: Traversing the map
value can be directly defined as:

value="#{"1":"a","2":"b"}"
Each element is separated by . 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 You can 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. The operation
label's attribute List can be written 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 one-to-one correspondence, one attrN corresponds to one attrV


index is :
attrName is : or
attrName is :


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!