Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

The example code for this tutorial, control_tags, is available for checkout at https://svngithub.com/apache.org/repos/asf/struts/sandbox/trunk/struts2examples/struts-examples

Introduction

Struts 2 has several control tags that can be used in the view. This tutorial will discuss and show examples of how to use the Struts 2 if and iterator tags. For more information about these and other control tags visit tags reference.

...

Code Block
html
1thankyou.jsp Struts if Tag
html


<s:if test="personBean.over21">

    <p>You are old enough to vote!</p>
    
</s:if>

<s:else>

   <p>You are NOT old enough to vote.</p>

</s:else>

...

Code Block
html
1thankyou.jsp Struts if Tag
html


<s:if test="personBean.carModels.length > 1">

	<p>Car models

</s:if>

<s:else>

   <p>Car model


</s:else>


...

Code Block
html
1thankyou.jsp Struts iterator Tag
html


<table style="margin-left:15px">
	
	<s:iterator value="personBean.carModels">
	
		<tr><td><s:property /></td></tr>

	</s:iterator>
		
</table>


...

Code Block
html
1thankyou.jsp Struts iterator Tag
html


<table style="margin-left:15px">

	<s:iterator value="states" >
	
		<tr><td><s:property value="stateAbbr" /></td> <td><s:property value="stateName" /></tr>

	</s:iterator>
	
</table>


...