Struts 2 Control Tags

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

Comments

comments

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.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better