such as <s:iterator value= "pmoperatelist" var= "LST" >
<!--iterator plus Var is equivalent to re-declaring the Pmoperatelist, the object is LST ensures a value-
Before the time without Var, has not been taken to the value, added after using ${lst.operateactionname} to display. It's out.
When you write java Code logic in the Struts tab of the JSP, add%{}, just like the normal JSP page with <%%> Java logic code
For example, compare:
<s:if test= "%{' addbigmerchantui ' = = #lst. Operateactionname}" >
Here also said, to invoke the value of just Var , need to add a #号and not alone Lst.operateactionname
The object in value is actually a list, with a list. The object is an error, and after Var it is a single object . The object is right.
You need to use the value inside the index, plus status= "index", plus after <s:property value= "#obj [index]" OK
Struts2 Top keyword
Before you explain top, learn about the value stack in the next struts2, and note that there are two points to be aware of in the stacks:
1). A value stack is essentially a list;
2). Call [n] in the stack to return a sub-stack starting at position N;
For the 2 example illustrate. Assuming that the value stack contains [A,b,c], then
1). [0]---return [a,b,c];
2). [1]---return [b,c];
3). [2]---return [c];
See the example below:
<s:set var= "Days" value= "{0,1,2,3,4,5,6}"/>
<s:iterator value= "#days" var= "Day" >
<s:property/>
</s:iterator>
Equivalent to
<s:set var= "Days" value= "{0,1,2,3,4,5,6}"/>
<s:iterator value= "#days" var= "Day" >
<s:property value= "Top"/>
</s:iterator>
Can be seen:
1). Top refers to the current iteration element , which can be an object;
2). Top available here [0].top substitution, but cannot use [0]; [0] represents the entire stack object. If simply calling [0] will call its toString () method to output object information;
So the above notation is also equivalent to:
<s:set var= "Days" value= "{0,1,2,3,4,5,6}"/>
<s:iterator value= "#days" var= "Day" >
<s:property value= "[0].top"/>
</s:iterator>
Knowing the meaning of top, we can do something about top:
<s:set var= "Days" value= "{0,1,2,3,4,5,6}"/>
<s:iterator value= "#days" var= "Day" >
<s:if test= "Top!=0" >
<s:property/>
</s:if>
</s:iterator>
Found: the <s:if test= "top!=0" > Changed to <s:if test= "top!= ' 0 '", add a single quotation mark, actually did not work, visible type requirements are very strict!
related use of iterator tags in struts2
Before explaining the use of the S:iterator label, understand the value Stack in the next struts2. The description of the value stack in WebWork is referenced here, and since Struts2 is upgraded on a webwork basis, WebWork's representation of the value stack also applies to struts2. Here does not describe what the value stack specifically does, but there are two points to note:
- A value stack is essentially a list;
- calling [n] in the stack will return a sub-stack starting from position n;
For the 2 example illustrate. Assuming that the value stack contains [model,action,others], then
- [0]---return [model,action,others];
- [1]---return [action,others];
- [2]---return [others];
You will now begin to introduce some of the uses of S:iterator. The following code snippets were passed using struts2.1.6 tests on the development environment eclipse3.4 WTP, tomcat5.5, Jdk5.
1), visit days
Defined list<string> days ["Monday", "Thursday", "Friday", "Sunday"]
[XHTML]View PlainCopy
- <s:iterator value="Days"><s:property /></s:iterator>
2), use the top keyword (filter out Monday)
Defined list<string> days ["Monday", "Thursday", "Friday", "Sunday"]
[XHTML]View PlainCopy
- <s:iterator value="Days">
- <s:if test="top!= ' Monday '">
- <s:property />
- </s:if>
- </s:iterator>
- Top refers to the current iteration element, which can be an object;
- The top here is available [0].top substitution, but cannot be used [0]. [0] represents the entire stack object. If simply calling [0] will call its ToString () method to output object information;
3), use last/first keyword
Defined string[][] ATs = {{"One", "two", "three", "four"},{"one by One", "22", "33", "44"}};
[XHTML] view plain copy
- <!--traversing a two-dimensional array, the trick here's to use ' top ' as the value for the inner iterator-->
- <s:iterator value="ATs" status="of">
- <s:if test="#of. Last"><br/></s:if>
- <s:iterator value="Top">
- <!--can also be replaced with [0].top. If [0] is used alone, the stack object information is printed at the same time-
- <s:property />
- </s:iterator>
- </s:iterator>
- The status attribute in the iterator tag represents the position of the current iteration;
- #of. Last is used to determine whether the current iteration to the element is the final element;
- Last returns a Boolean type;
- First returns a Boolean type;
4), use odd/even keywords
The following example implements a different color effect for each row of output.
Defined list<string> days ["Monday", "Thursday", "Friday", "Sunday"]
[XHTML]View PlainCopy
- <!--odd rows are shown in red, even rows are green--
- <s:iterator value="Days" status="offset">
- <s:else>
- <s:if test="#offset. Odd==true">
- <li style="color:red" mce_style="color:red"><s:property /> </li>
- </s:if>
- <s:else>
- <li><s:property /></li>
- </s:else>
- </s:else>
- </s:iterator>
- The odd keyword is used to determine whether the current iteration position is an odd line. Odd returns a Boolean type;
- The even keyword is used to determine whether the current iteration position is an even row. Even returns a Boolean type
5), in summary, when declaring the status property of iterator, the following methods can be used #statusName. Method:
- Even:boolean-Returns True if the current iteration position is even
- Odd:boolean-Returns True if the current iteration position is odd
- Count:int-Returns the count of the current iteration position (starting at 1)
- Index:int-Returns the number of the current iteration position (starting at 0)
- First:boolean-Returns True if the current iteration position is the first bit
- Last:boolean-Returns True if the current iteration position is the last one
- Modulus (operand:int): INT-Returns the current count (starting from 1) and the modulus of the specified operand
6), and finally look at the use of the call value stack in iterator.
Suppose countries is a list object, each country has a Name property and a Citys list object, and each city also has a name property. Then we want to access the Name property of the owning country when iterating over Citys, as in the following way:
[XHTML]View PlainCopy
- <s:iterator value="Countries">
- <s:iterator value="Cities">
- <s:property value="name"/>, <s:property value="[1].name"/> <br>
- </s:iterator>
- </s:iterator>
- Here the <ww:property value= "name"/> Taken is Ctiy.name;<ww:property value= "[1].name"/> Obtained is Country.Name
- <ww:property value= "[1].name"/> equivalent to <ww:property value= "[1].top.name]/>
- We refer to a specific position on the stack: ' [1] '. The top of the stack, position 0, contains, pushed on by the inner iterator; Position 1 contains the current country, pushed there by the outer iterator. (city is in the current stack, top or [0], while [1] indicates the outer iterator object, or country)
- The ' [n] ' tag refers to the sub-stack (sub-stack) where the start position is N, not just the object at position N. So ' [0] ' represents the entire stack, and ' [1] ' is all the stack elements except the top object.
Turn: Struts2<s:iterator value= "" var= "LST" > the use of Var and some of the use of the label experience