Home php教程 PHP开发 Detailed explanation of the use of s:iterator tag in struts2

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

Dec 13, 2016 pm 05:38 PM

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 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)