- Struts2 - Annotations
- Struts2 - Exception Handling
- Struts2 - Themes/Templates
- Struts2 - Type Conversion
- Struts2 - Localization
- Struts2 - Validations
- Struts2 - Sending Email
- Struts2 - Database Access
- Struts2 - File Uploads
- Struts2 - Value Stack/OGNL
- Struts2 - Result Types
- Struts2 - Interceptors
- Struts2 - Actions
- Struts2 - Configuration
- Struts2 - Examples
- Struts2 - Architecture
- Struts2 - Environment Setup
- Struts2 - Overview
- Struts2 - Basic MVC Architecture
- Struts2 - Home
Struts 2 Tags
Struts 2 Integrations
Struts 2 Useful Resources
- Struts2 - Discussion
- Struts2 - Useful Resources
- Struts2 - Quick Guide
- Struts2 - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Struts 2 - Control Tags
The Struts 2 tags has a set of tags that makes it easy to control the flow of page execution.
Following is the pst of important Struts 2 Control Tags −
The If and Else Tags
These tags perform basic condition flow found in every language.
If tag is used by itself or with Else If Tag and/or single/multiple Else Tag as shown below −
<s:if test = "%{false}"> <span>Will Not Be Executed</span> </s:if> <s:elseif test = "%{true}"> <span>Will Be Executed</span> </s:elseif> <s:else> <span>Will Not Be Executed</span> </s:else>
The Iterator Tags
This iterator will iterate over a value. An iterable value can be either itherjava.util.Collection or java.util.Iterator file. While iterating over an iterator, you can use Sort tag to sort the result or SubSet tag to get a sub set of the pst or array.
The following example retrieves the value of the getDays() method of the current object on the value stack and uses it to iterate over.
The <s:property/> tag prints out the current value of the iterator.
<s:iterator value = "days"> <p>day is: <s:property/></p> </s:iterator>
The Merge Tag
These merge tag takes two or more psts as parameters and merge them all together as shown below −
<s:merge var = "myMergedIterator"> <s:param value = "%{myList1}" /> <s:param value = "%{myList2}" /> <s:param value = "%{myList3}" /> </s:merge> <s:iterator value = "%{#myMergedIterator}"> <s:property /> </s:iterator>
The Append Tag
These append tag take two or more psts as parameters and append them all together as shown below −
<s:append var = "myAppendIterator"> <s:param value = "%{myList1}" /> <s:param value = "%{myList2}" /> <s:param value = "%{myList3}" /> </s:append> <s:iterator value = "%{#myAppendIterator}"> <s:property /> </s:iterator>
The Generator Tag
These generator tag generates an iterator based on the val attribute suppped. The following generator tag generates an iterator and prints it out using the iterator tag.
<s:generator val = "%{ aaa,bbb,ccc,ddd,eee }"> <s:iterator> <s:property /><br/> </s:iterator> </s:generator>
Advertisements