You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2014/07/10 08:20:19 UTC

svn commit: r915642 - /websites/production/struts/content/development/2.x/docs/struts-control-tags.html

Author: lukaszlenart
Date: Thu Jul 10 06:20:19 2014
New Revision: 915642

Log:
Updates production

Modified:
    websites/production/struts/content/development/2.x/docs/struts-control-tags.html

Modified: websites/production/struts/content/development/2.x/docs/struts-control-tags.html
==============================================================================
--- websites/production/struts/content/development/2.x/docs/struts-control-tags.html (original)
+++ websites/production/struts/content/development/2.x/docs/struts-control-tags.html Thu Jul 10 06:20:19 2014
@@ -37,6 +37,7 @@ under the License. 
     <link href='http://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
     <link href='http://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
     <script src='http://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
+    <script src='http://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
     <script src='http://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
 
     <script type="text/javascript">
@@ -146,61 +147,35 @@ under the License. 
                             <p>The <a shape="rect" class="external-link" href="http://struts.apache.org/mail.html">Struts 2 user mailing list</a> is an excellent place to get help. If you are having a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don't find an answer to your problem, post a question on the mailing list.</p>
                     </div>
     </div>
-<h3 id="StrutsControlTags-Struts2ifTag">Struts 2 if Tag</h3><p>In the example application's thankyou.jsp is this markup.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;s:if test=&quot;personBean.over21&quot;&gt;
-
+<h3 id="StrutsControlTags-Struts2ifTag">Struts 2 if Tag</h3><p>In the example application's thankyou.jsp is this markup.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>thankyou.jsp Struts if Tag</b></div><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;s:if test=&quot;personBean.over21&quot;&gt;
     &lt;p&gt;You are old enough to vote!&lt;/p&gt;
-    
 &lt;/s:if&gt;
-
 &lt;s:else&gt;
-
    &lt;p&gt;You are NOT old enough to vote.&lt;/p&gt;
-
 &lt;/s:else&gt;
-
 ]]></script>
 </div></div><p>The Struts if tag has a test attribute. The value of the test attribute must evaluate to true or false. If true the statements between the opening and closing s:if tags will be executed. If false, the statements between the opening and closing s:else tags will be executed. Note that s:else tags come after the closing s:if tag and that the s:else tags are not required.</p><p>In the above example the Struts framework will call method getPersonBean exposed by the Action class (EditAction.java). Using the Person object returned by that method, the framework will then call method isOver21 of class Person. That method returns a boolean that will be used to determine if the test is true or false.</p><p>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.</p><div class="code panel pdl" style="border
 -width: 1px;"><div class="codeContent panelContent pdl">
-<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;s:if test=&quot;personBean.carModels.length &gt; 1&quot;&gt;
-
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;s:if test=&quot;personBean.carModels.length &gt; 1&quot;&gt;
 	&lt;p&gt;Car models
-
 &lt;/s:if&gt;
-
 &lt;s:else&gt;
-
    &lt;p&gt;Car model
-
-
 &lt;/s:else&gt;
-
-
 ]]></script>
 </div></div><p>The purpose of the above markup is to use either "Car model" or "Car models" depending on how many car models the user selected on the edit page. So the value for the test attribute of this iterator tag gets the length of the carModels String array and compares that to 1. If it's greater then 1, the correct grammar is "Car models" else the correct grammar is "Car model".</p><h3 id="StrutsControlTags-StrutsiteratorTag">Struts iterator Tag</h3><p>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.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
 <script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;table style=&quot;margin-left:15px&quot;&gt;
-	
 	&lt;s:iterator value=&quot;personBean.carModels&quot;&gt;
-	
 		&lt;tr&gt;&lt;td&gt;&lt;s:property /&gt;&lt;/td&gt;&lt;/tr&gt;
-
 	&lt;/s:iterator&gt;
-		
 &lt;/table&gt;
-
-
 ]]></script>
 </div></div><p>The goal of this code is to create an HTML table with a row that display a car model selected by the user on the edit page. The car models the user selects on the edit page are stored in the carModels field (a String array) of the personBean object (of class Person).</p><p>The iterator tag has a value attribute that must evaluate to a collection (Array, List, Map).</p><p>The s:property tag nested inside the iterator tag is used to display the specific value of the collection each time the iterator loops over an element of the collection. Since the collection is an Array of String objects, the s:property tag doesn't need to specify a value attribute. By default the s:property tag will display the single String for that element of the collection.</p><p>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:</p><div class="code panel pdl" style="border-wid
 th: 1px;"><div class="codeContent panelContent pdl">
-<script class="theme: Default; brush: html; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;table style=&quot;margin-left:15px&quot;&gt;
-
-	&lt;s:iterator value=&quot;states&quot; &gt;
-	
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[&lt;table style=&quot;margin-left:15px&quot;&gt;
+	&lt;s:iterator value=&quot;states&quot; &gt;	
 		&lt;tr&gt;&lt;td&gt;&lt;s:property value=&quot;stateAbbr&quot; /&gt;&lt;/td&gt; &lt;td&gt;&lt;s:property value=&quot;stateName&quot; /&gt;&lt;/tr&gt;
-
 	&lt;/s:iterator&gt;
-	
 &lt;/table&gt;
-
-
 ]]></script>
 </div></div><p>The value of the iterator tag is states, which causes the Struts 2 framework to call the getStates method of the Action class (EditAction.java). The getStates method returns a List of State objects. The State class has two fields stateAbbr and stateName, both having the appropriate get method. The iterator will loop over each State object stored in the collection. Each time through the loop, the Struts 2 framework will have a reference to the current State object and will call getStateAbbr and getStateName methods for that current State object.</p><h3 id="StrutsControlTags-AdditionalIteratorAttributes">Additional Iterator Attributes</h3><p>The Struts 2 iterator tag has additional attributes you can use to control the begin and end values for specifying that the iterator tag should only loop over a part of the collection. See the <a shape="rect" href="https://cwiki.apache.org/confluence/display/WW/iterator">iterator tag reference</a> for more information.</p></div>
         </div>