The page uses the struts2 tag to get the object attribute values in the list, STRUTS2 common tag summaries _struts2

Source: Internet
Author: User
Tags set set
The page uses the struts2 tag to get the object attribute value in the list, Struts2 common tag summary struts2 tag list

<% @taglib prefix= "s" uri= "/struts-tags"%>

<s:iterator value= "list" status= "Statu" >

<s:property value= "Name"/>

<s:property value= "Sex"/>

<s:property value= "Address"/>

</s:iterator>

Turn from: http://www.iteye.com/problems/2147

Struts2 Common Label Summary
An introduction
1. The role of STRUTS2
The STRUTS2 tag Library provides themes, template support, greatly simplifies the authoring of view pages, and struts2 themes and templates provide good extensibility. Better code reuse is achieved. STRUTS2 allows custom components to be used on the page, which can fully meet the complexity and variability of the page display in the project.
STRUTS2 's tag library has a huge improvement, struts2 tag library labels do not rely on any presentation technology, which means that STRTUS2 provides most of the tags that can be used in a variety of performance technologies. Includes the most commonly used JSP pages, and can also be said to be used in template technologies such as velocity and freemarker
2. STRUTS2 classification
(1) UI Tags: (user Interface, UI) tags, mainly used to generate HTML element tags, UI tags can be divided into form labels and non-form labels
(2) Non-UI tags, mainly used for data access, logic control, and other labels. Non-UI tags can be divided into process control tags (including those used to implement process control such as branching, looping, and so on) and data access tags (mainly including values in user output Valuestack, complete internationalization, etc.)
(3) Ajax tags
3. Preparation of Struts2 label before use:
(1) Introduce the tag library in the JSP page to use the label:
<%@ taglib uri= "/struts-tags" prefix= "s"%>
(2) Declare the label to be used in Web.xml this is the introduction of the STRUTS2 2.3.1.2 Version
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
4. Use of labels
(1) Property label
Used to output the specified value:
<s:property value= "%{@cn. Csdn.hr.domain.user@name}"/><br/>
<s:property value= "@cn. Csdn.hr.domain.user@name"/><br/><!--Both of these methods can be-->
<s:property value= "%{@cn. Csdn.hr.domain.user@study ()}"/>
The above is a centralized way of accessing the properties of a class of a package, and study () is the method of accessing the method and outputting it.


The following is a Java code instead of accessing a range of properties
<%
Use the PageContext object to store values in the page range to verify that the #attr search order starts with page, and the search order is: page,reques,session,application.
Set value is stored in the request, in the JSP page access without adding any identifiers, you can directly access, if different scopes,
Pagecontext.setattribute ("name", "Laoowang", Pagecontext.page_scope);
%>
<s:property value= "#attr. Name"/>


Suppose a class with different scopes is set in the action
Access to different scopes of labels:

The first way: <s:property value= "#request. User1.realname"/>
<br/>
The second way: <s:property value= "#request. user1[' realname ']"/>
<br/>
The Third Way: <s:property value= "#user1. Realname"/>
<br/>
The fourth way: <s:property value= "#user1 [' realname ']"/>
<br/>
The fifth way: ${requestscope.user1.realname} | | ${requestscope.user1[' Realname ']}

Type sixth: <s:property value= "#attr. User1.realname"/>
attr Object Press page==> request Sessionapplictio to find


The first way: <s:property value= "#session. User1.realname"/>
<br/>
The second way: <s:property value= "#session. user1[' realname ']"/>


The fifth way: ${sessionscope.user1.realname} | | ${sessionscope.user1[' Realname ']}

The first way: <s:property value= "#application. User1.realname"/>
<br/>
The second way: <s:property value= "#application. user1[' realname ']"/>


The fifth way: ${applicationscope.user1.realname} | | ${applicationscope.user1[' Realname ']}

(2) The use of iterator label
First: List collection
<!--sets Set set value-->
<!--Status Optional property that specifies the Iteratorstatus instance at the time of the iteration-->
<!--value= "#attr. List" list is stored in the request to value= "#request. List"
Statu.odd returns whether the index of the currently iterated element is odd
-->
<s:set name= "List" value= "{' A ', ' B ', ' C ', ' d '}" ></s:set>
<s:iterator var= "ent" value= "#request. List" status= "Statu" >
<s:if test= "%{#statu. Odd}" >
<font color= "Red" ><s:property value= "#ent"/>
</font>
</s:if>
<s:else>
<s:property value= "#ent"/>
</s:else>
</s:iterator>

Second: use in the Map collection
<!--Map Collection features:
Syntax format: # {Key:value,key1:value1,key2:value2,.....}
In the syntax above, a collection of map types is generated directly between each Key-value object in the Map object, separated by a colon in English
, multiple elements are separated by commas.
-->
</div>

<s:set var= "Map" value= "#{' 1": ' Laowang ', ' 2 ': ' Lao Wang ', ' 3 ': ' Orangutan '} ' ></s:set>
Traverse Map:
<br/>
<s:iterator value= "#map" >
<s:property value= "key"/>:::<s:property value= "value"/>
<br/>
</s:iterator>\

Third: The variables of the collection
   <div>
    <! --Traverse out the price is greater than 3000 of the     <s:iterator
var= "user" value= "#session [' Users ']" "
     <s:if test= "%{#user [' Price ']>3000}"
       <s:property value= "#user [' Price ']"/>
     </s:if>
     </s:iterator>
    
    
          <s:iterator var= "U" Value= "#session. Users. {$ (#this [' Price ']>3000]} "
     <s:property value=" Price "/>
     </s:iterator>
   </div>
Note: Users are objects of user, Price is a property in user

Briefly describes the introduction of iterator:
The iterator tag is used to iterate over the collection, where the collection contains the list, set, and array.
<s:set name= "list" value= "{' zhangming ', ' xiaoi ', ' liming '}"/>
<s:iterator value= "#list" status= "St"
 <font color=<s:if test= "#st. Odd" >red</s:if><s:else>blue</s:else>>
 <s:property/></font><br>
</s:iterator> 
Value: Optional property, specifying the collection of iterations. If this property is not set, then the collection on the top of the Valuestack stack is used.
ID: An optional property that specifies the ID of the element in the collection.
Status: An optional property that specifies the Iteratorstatus instance at the time of the iteration. The instance contains several methods:
 int GetCount (), which returns several elements of the current iteration.
 int GetIndex (), which returns the index of the current iteration element. The
 boolean IsEven () returns whether the index of the currently iterated element is an even
 boolean isodd (), which returns whether the index of the currently iterated element is an odd
 boolean Isfirst ( Returns whether the currently iterated element is the first element. The
 boolean islast () returns whether the currently iterated element is the last element.


(3) If Else statement uses
 <s:set name= "age" value= "/>
<s:if test=" #age ==23 "
 23
</s:if>
<s:elseif test= "#age ==21"
 21
</s:elseif>
<s:else>
  is not equal to
</s:else>

(4) URL tag
<!--declare a URL address-->
<s:url action= "test" namespace= "/tag" var= "Add" >
<s:param name= "username" >laowangang</s:param>
<s:param name= "id" >12</s:param>
</s:url>
<s:a href= "%{add}" > Test url</s:a>
<s:a action= "test" namespace= "/tag" ></s:a>
The above two <s:a> tags have the same effect.
(5) Data label
<%
Pagecontext.setattribute ("Birth", New Date (200,03,10), pagecontext.request_scope);
%>
<s:date name= "#request. Birth" format= "yyyy year mm month DD Day"/>
<s:date name= "#request. Birth" nice= "true"/>
The label is printed in the format.

(6) Form


<s:form action= "test" namespace= "/tag" >
<s:textfield label= "username" name= "uname" tooltip= "Your Name" javascripttooltip= "false" ></s:textfield>
<s:textarea name= "Rmake" cols= "rows=" tooltipdelay= "a" tooltip= "Hi" label= "Remarks" javascripttooltip= "true" ></s:textarea>
<s:password label= "Password" name= "UPass" ></s:password>
<s:file name= "file" label= "Uploading Files" ></s:file>
<s:hidden name= "id" value= "1" ></s:hidden>

<!--
<select name= "Edu" >
<option value= "Listkey" >listValue</option>
-->
<s:select list= "#{' 1 ': ' Dr ', ' 2 ': ' Master '}" name= "edu" label= "education" listkey= "key" listvalue= "value" ></s:select>

<s:select list= "{' Java ', '. Net '}" Value= "Java" ></s:select><!--value is selected-->

<!--must have name-->
<s:checkbox label= "Love" fieldvalue= "true" Name= "checkboxFiled1" ></s:checkbox>

<!--multiple checkbox-->
<s:checkboxlist list= "{' Java ', ' CSS ', ' html ', ' struts2 '}" label= "Favorite programming language" name= "box" value= "{' css ', ' struts2 '}" > </s:checkboxlist>


Add #--> before <!--map Collection
<s:checkboxlist list= "#{1: ' Java ', 2: ' CSS ', 3: ' HTML ', 4: ' Struts2 ', 5: ' Spring '}" label= "Preferred programming language" name= "Boxs" value= "{ 1,2} "></s:checkboxlist>


<!--Listkey
ListValue

<input type= "text" name= "Boxs" value= "Listkey" > Display value ListValue
-->

<!--Radio-->
<%
The value passed from the server.
Pagecontext.setattribute ("Sex", "male", pagecontext.request_scope);
Pagecontext.setattribute ("Sex1", "male", pagecontext.request_scope);
%>
<s:radio list= "{' Male ', ' female '}" name= "Sex" value= "#request. Sex" ></s:radio>


<s:radio list= "#{1: ' Male ', 2: ' Female '}" Name= "Sex1" listkey= "key" listvalue= "value" value= "#request. Sex1" ></s:radio >

<!--ways to prevent form submissions-->
<s:token></s:token>

<s:submit value= "Submit" ></s:submit>
</s:form>

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.