• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

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

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.

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

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.

<s:iterator value="employees">
	Employee name : <s:property name="name"/>
</s:iterator>

Read More : Iterator Tag Tutorial

3. The merge tags

The merge tags is useful for merging the two lists.

<s:merge var="alldata">
     <s:param value="data1" />
     <s:param value="data2" />
</s:merge>
<s:iterator value="alldata">
     <s:property />
</s:iterator>

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.

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

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.

<s:generator val="%{'data1,data2,data3,data4'}">
 <s:iterator>
     <s:property /><br/>
 </s:iterator>
</s:generator>

Read More : Iterator Tag Tutorial

Category: StrutsTag: 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.

Previous Post: « Struts 2 Generator Tag Example
Next Post: Difference Between FilterDispatcher and StrutsPrepareAndExecuteFilter in Struts 2 »

Reader Interactions

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.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact