Return-Path: X-Original-To: apmail-struts-commits-archive@minotaur.apache.org Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4A3A4118D6 for ; Thu, 10 Jul 2014 06:20:20 +0000 (UTC) Received: (qmail 64113 invoked by uid 500); 10 Jul 2014 06:20:19 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 64080 invoked by uid 500); 10 Jul 2014 06:20:19 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 64071 invoked by uid 99); 10 Jul 2014 06:20:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jul 2014 06:20:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jul 2014 06:20:17 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 85E7B23888D2 for ; Thu, 10 Jul 2014 06:19:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r915641 - /websites/production/struts/content/release/2.3.x/docs/struts-control-tags.html Date: Thu, 10 Jul 2014 06:19:57 -0000 To: commits@struts.apache.org From: lukaszlenart@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140710061957.85E7B23888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lukaszlenart Date: Thu Jul 10 06:19:57 2014 New Revision: 915641 Log: Updates production Modified: websites/production/struts/content/release/2.3.x/docs/struts-control-tags.html Modified: websites/production/struts/content/release/2.3.x/docs/struts-control-tags.html ============================================================================== --- websites/production/struts/content/release/2.3.x/docs/struts-control-tags.html (original) +++ websites/production/struts/content/release/2.3.x/docs/struts-control-tags.html Thu Jul 10 06:19:57 2014 @@ -37,6 +37,7 @@ under the License. +

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.

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.

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.

-

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".

Struts iterator Tag

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.

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).

The iterator tag has a value attribute that must evaluate to a collection (Array, List, Map).

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.

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:

-

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.

Additional Iterator Attributes

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 iterator tag reference for more information.