JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy

Struts 2 Control Tags

December 13, 2013 by Krishna Srinivasan Leave a Comment

Struts 2 provides list of conditional or control tags which is very useful for controlling the flow of an application. The following are the list of important tags listed under conditional tags.

  1. If and else
  2. Iterator
  3. Merge
  4. Append
  5. Generator

1. The if and else tags

This tag is useful for executing the simple if or else condition by taking the values from a variable. It is very similar to the one used in every language.

[code lang=”xml”]
<s:if test="condition">
This is executed if first one is matched
</s:if>
<s:elseif test="condition">
This is executed if first one is not matched and this is matched
</s:elseif>
<s:else>
If no condition is matching, this code will be executed.
</s:else>[/code]

Read More : If and else tag tutorial

2. The iterator tags

The iterator tags are useful for iterating list of objects like ArryList, Map, etc. in the convenient manner. It is the customized using the custom tags for simplifying the iteration process.Property tag inside this tag will be used for retriving the field values for the parent object.

[code lang=”xml”]<s:iterator value="employees">
Employee name : <s:property name="name"/>
</s:iterator>[/code]

Read More : Iterator Tag Tutorial

3. The merge tags

The merge tags is useful for merging the two lists.

[code lang=”xml”]
<s:merge var="alldata">
<s:param value="data1" />
<s:param value="data2" />
</s:merge>
<s:iterator value="alldata">
<s:property />
</s:iterator>
[/code]

Read More : Merge Tag Tutorial

4. The append tags

The append tags in Struts 2 append the two or more lists into a single iterator.

[code lang=”xml”]
<s:append var="allAppendData">
<s:param value="data1" />
<s:param value="data2" />
<s:param value="data3" />
</s:append>
<s:iterator value="allAppendData">
<s:property />
</s:iterator>[/code]

5. The generator tags

The generator tag is simple tag to iterate a list of object passed to the attribute. This tag enclosed with another iterator tag.

[code lang=”xml”]
<s:generator val="%{‘data1,data2,data3,data4’}">
<s:iterator>
<s:property /><br/>
</s:iterator>
</s:generator>[/code]

Read More : Iterator Tag Tutorial

Filed Under: Struts Tagged With: Struts 2 Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved