Info |
---|
The example code for this tutorial, control_tags, is available for checkout at https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/ |
Introduction
...
In the example application's thankyou.jsp is this markup.
Code Block | |||||||
---|---|---|---|---|---|---|---|
| |||||||
<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.
Code Block | |||||||
---|---|---|---|---|---|---|---|
| |||||||
<s:if test="personBean.carModels.length > 1"> <p>Car models </s:if> <s:else> <p>Car model </s:else> |
...
The Struts iterator tag is used to generate a loop that iterates over each item in a collection. In the thankyou.jsp is this markup.
Code Block | |||||||
---|---|---|---|---|---|---|---|
| |||||||
<table style="margin-left:15px"> <s:iterator value="personBean.carModels"> <tr><td><s:property /></td></tr> </s:iterator> </table> |
...
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
<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> |
...