Versions Compared

Key

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

...

In the example application's thankyou.jsp is this markup.

Code Block
html1thankyou.jsp Struts if Tag
languagexml
titlethankyou.jsp Struts if Taghtml
<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>

...

The value of the test attribute must be an expression that evaluates to true or false, but doesn't need to be a method call that returns a boolean. For example this s:if tag that is in thankyou.jsp has a more complicated expression.

html
Code Block
1thankyou.jsp Struts if Tag
languagexmlhtml
<s:if test="personBean.carModels.length > 1">

	<p>Car models

</s:if>

<s:else>

   <p>Car model


</s:else>


...

If the collection contains objects that have multiple fields, then you should use the value attribute of the s:property tag to determine what field to display. For example:

Code Block
html1thankyou.jsp Struts iterator Tag
languagehtmlxml
<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>


...