Struts 2 Control Tags

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:elseif test="condition">
    This is executed if first one is not matched and this is matched
    If no condition is matching, this code will be executed.

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

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:iterator value="alldata">
     <s:property />

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:iterator value="allAppendData">
     <s:property />

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:property /><br/>

Read More : Iterator Tag Tutorial

Leave a Reply

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

Pin It on Pinterest

Share This

Share this post with your friends!