struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [08/13] struts-site git commit: cleaned up the form-tags page
Date Sun, 02 Apr 2017 09:13:09 GMT
cleaned up the form-tags page


Project: http://git-wip-us.apache.org/repos/asf/struts-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-site/commit/338b55ff
Tree: http://git-wip-us.apache.org/repos/asf/struts-site/tree/338b55ff
Diff: http://git-wip-us.apache.org/repos/asf/struts-site/diff/338b55ff

Branch: refs/heads/master
Commit: 338b55ff63f74defb3bc773ff0038141a9b4aeb5
Parents: a416395
Author: Stefaan Dutry <stefaan.dutry@gmail.com>
Authored: Sun Apr 2 09:03:10 2017 +0200
Committer: Stefaan Dutry <stefaan.dutry@gmail.com>
Committed: Sun Apr 2 09:03:10 2017 +0200

----------------------------------------------------------------------
 source/getting-started/form-tags.md | 103 +++++++++----------------------
 1 file changed, 30 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts-site/blob/338b55ff/source/getting-started/form-tags.md
----------------------------------------------------------------------
diff --git a/source/getting-started/form-tags.md b/source/getting-started/form-tags.md
index fd36cc4..baa7bcc 100644
--- a/source/getting-started/form-tags.md
+++ b/source/getting-started/form-tags.md
@@ -6,19 +6,13 @@ title: Form tags
 
 The example code for this tutorial, form_tags, can be checked out from [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples).
 
-> 
+__Introduction__
 
-#####Introduction#####
+In this tutorial we'll explore some of the other Struts 2 form controls. In our previous
tutorials that explained how to use Struts 2 forms ([Processing Forms](processing-forms.html)
, [Form Validation](form-validation.html) , and [Message Resource Files](message-resource-files.html)
) we covered how to use the Struts 2 head, form, textfield controls and the key attribute.
This tutorial will explore using the Struts 2 select, radio, checkbox, and checkboxlist form
controls.
 
-In this tutorial we'll explore some of the other Struts 2 form controls. In our previous
tutorials that explained how to use Struts 2 forms (_Processing Forms_ , _Form Validation_
, and _Message Resource Files_ ) we covered how to use the Struts 2 head, form, textfield
controls and the key attribute. This tutorial will explore using the Struts 2 select, radio,
checkbox, and checkboxlist form controls.
+The [Struts 2 user mailing list](http://struts.apache.org/mail.html) 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.
 
-
-
-| The [Struts 2 user mailing list](http://struts.apache.org/mail.html)^[http://struts.apache.org/mail.html]
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.
-
-| 
-
-#####Example Application#####
+__Example Application__
 
 The example application that supports this tutorial shows how to use Struts 2 form tags so
that a user can edit his information. The information that can be edited is encapsulated in
an object of class Person. A Person object knows these things: first name, last name, favorite
sport, gender, state of residency, is or is not over 21, and car models owned.
 
@@ -30,30 +24,20 @@ The form allows the user to make changes. After submitting the form, the
Struts
 
 The first and last names are shown on the form (see edit.jsp) using the Struts 2 textfield
tag, which we've discussed in previous tutorials.
 
-#####Struts 2 Select Tag#####
+__Struts 2 Select Tag__
 
 A user can select one favorite sport from several choices. The example application uses the
Struts 2 select tag to provide the list of options for the select box.
 
 **Struts 2 Select Tag**
 
-
-~~~~~~~
+```html
 <s:select key="personBean.sport" list="sports" />
+```
 
-
-~~~~~~~
-
-In these form tags, we are using the key attribute as discussed in the _Message Resource
Files_  tutorial. The key attribute is used by the Struts 2 framework to determine values
for the other attributes (e.g. label and value). We are also using a property file associated
with the EditAction class to provide the label values based on the key attribute value (see
the _Message Resource Files_  tutorial for information on using Struts 2 property files).
-
-
-> 
-
-> 
+In these form tags, we are using the key attribute as discussed in the [Message Resource
Files](message-resource-files.html) tutorial. The key attribute is used by the Struts 2 framework
to determine values for the other attributes (e.g. label and value). We are also using a property
file associated with the EditAction class to provide the label values based on the key attribute
value (see the [Message Resource Files](message-resource-files.html) tutorial for information
on using Struts 2 property files).
 
 > Note that there are many attributes for the Struts 2 form tags, most of which mirror
the HTML attributes associated with the tags. You can read about all the attributes for a
Struts 2 form tag by consulting the Struts 2 documentation.
 
-> 
-
 The value of the list attribute of the Struts 2 select tag is used by the framework to determine
what method of the action class to call in order to create the option values. In our example
application, the list attribute value of "sports" results in the framework calling the getSports
method of class EditAction. That method returns a String array containing "football", "baseball",
and "basketball". Those values are used to create the option tags inside the select tag.
 
 The Struts 2 framework determines which option is preselected by using the key attribute's
value to call a method on the personBean object. Since the key attribute's value is "personBean.sport",
the framework calls the personBean object's getSport method. If the value returned by that
method matches one of the option values, that option will be marked as "selected".
@@ -62,8 +46,7 @@ Here is the HTML that results from using the above Struts 2 select tag.
 
 **HTML Created By Struts 2 Select Tag**
 
-
-~~~~~~~
+```html
 <tr>
 <td class="tdLabel">
 <label for="save_personBean_sport" class="label">Favorite sport:</label>
@@ -76,33 +59,27 @@ Here is the HTML that results from using the above Struts 2 select tag.
 </select>
 </td>
 </tr>
-
-
-~~~~~~~
+```
 
 Note the table formatting created by the Struts 2 framework when using the Struts 2 select
tag. The CSS classes are defined in style sheets included by the Struts 2 s:head tag. The
Struts 2 s:head tag is placed inside the edit.jsp's head section.
 
 Since the personBean's getSport method returns "baskeball", the basketball option value is
marked as selected.
 
-#####Struts 2 Radio Tag#####
+__Struts 2 Radio Tag__
 
 The Struts 2 radio tag—like its standard HTML counterpart—is used to display 2 or more
choices, only one of which can be selected by the user. Here is the code for the Struts 2
radio button from the example application.
 
 **Struts 2 Radio Tag**
 
-
-~~~~~~~
+```html
 <s:radio key="personBean.gender" list="genders" />
-
-
-~~~~~~~
+```
 
 Again the key attribute's value determines the value for the label and value attributes.
The label's text is derived from the EditAction.properties file (key personBean.gender). Just
like the Struts 2 select tag, the list attribute of the Struts 2 radio tag causes the framework
to call the getGenders method of the EditAction class. The Array of String objects returned
are used to create the individual radio buttons.
 
 **HTML Created By Struts 2 Radio Tag**
 
-
-~~~~~~~
+```html
 <tr>
 <td class="tdLabel">
 <label for="save_personBean_gender" class="label">Gender:</label></td>
@@ -112,24 +89,19 @@ Again the key attribute's value determines the value for the label and
value att
 <input type="radio" name="personBean.gender" id="save_personBean_gendernot sure" checked="checked"
value="not sure"/><label for="save_personBean_gendernot sure">not sure</label>
 </td>
 </tr>
-
-
-~~~~~~~
+```
 
 Also just like the Struts 2 select tag the result returned by calling the personBean object's
getGender method is used to determine which of the radio buttons is checked.
 
-#####Struts 2 Select Tag - Object Backed#####
+__Struts 2 Select Tag - Object Backed__
 
 You may need to create a Struts 2 select tag where the options displayed to the user each
have their own value that is different then what is displayed. In the example application,
the user's residency is stored as a two-letter abbreviation (e.g. KS), but the form select
box should display the full state name (e.g. Kansas). To create such a select box in Struts
2, you would use this code
 
 **Struts 2 Select Tag Object Backed**
 
-
-~~~~~~~
+```html
 <s:select key="personBean.residency" list="states" listKey="stateAbbr" listValue="stateName"
/>
-
-
-~~~~~~~
+```
 
 The list value tells the framework to call the getStates method of the EditAction class.
That method returns an ArrayList of State objects. Each State object has getStateAbbr and
getStateName methods.
 
@@ -137,8 +109,7 @@ The listKey attribute tells the framework to use the value returned by
calling t
 
 **HTML Created By Struts 2 Select Tag**
 
-
-~~~~~~~
+```html
 <tr>
 <td class="tdLabel">
 <label for="save_personBean_residency" class="label">State resident:</label></td>
@@ -152,31 +123,25 @@ The listKey attribute tells the framework to use the value returned
by calling t
 </select>
 </td>
 </tr>
-
-
-~~~~~~~
+```
 
 The value returned by calling the personBean object's getResidency method determines which
of the select tag's option tags is marked as selected. In our example, since getResidency
returns "KS", the option tag whose value attribute equals "KS" is marked as selected.
 
-#####Struts 2 Checkbox Tag#####
+__Struts 2 Checkbox Tag__
 
 The Struts 2 checkbox tag is used to create the HTML input type equals checkbox tag. The
value for the key attribute tells the framework what method to call to determine if the checkbox
is checked or not checked. The method called should return a Boolean value (true or false).
A return value of true will cause the checkbox to be checked and false the checkbox will not
be checked.
 
 **Struts 2 Checkbox Tag**
 
-
-~~~~~~~
+```html
 <s:checkbox key="personBean.over21" />
-
-
-~~~~~~~
+```
 
 Since the method getOver21 returns true, the checkbox is checked.
 
 **HTML Created By Struts 2 Checkbox Tag**
 
-
-~~~~~~~
+```html
 <tr>
 <td valign="top" align="right">
 </td>
@@ -185,15 +150,13 @@ Since the method getOver21 returns true, the checkbox is checked.
 <input type="hidden" id="__checkbox_save_personBean_over21" name="__checkbox_personBean.over21"
value="true" />  <label for="save_personBean_over21" class="checkboxLabel">21 or
older</label>
 </td>
 </tr>
-
-
-~~~~~~~
+```
 
 When the form is submitted and the checkbox is not checked, no value will be posted for the
checkbox (this is how HTML forms work). Since the Struts 2 framework will need to update the
value of the personBean's over21 instance field to false—given that the check box was not
checked—the framework needs a way to determine if the checkbox was not checked after form
submission.
 
 If you examine the HTML code created by the Struts 2 checkbox tag, you'll see that it created
a hidden field associated with the personBean.over21 checkbox. When the Struts 2 framework
intercepts the submission of this form it will use this hidden form field to check if the
associated checkbox field exists in the posted form data. If that checkbox field doesn't exist
then the Struts 2 framework will know to update the value of the personBean object's over21
instance variable to false.
 
-#####Struts 2 checkboxlist Tag#####
+__Struts 2 checkboxlist Tag__
 
 The Struts 2 framework provides a unique form field control that creates a series of associated
check boxes, one or more of which can be checked. In the example application, the Person class
has an Array of Strings, which is used to store car models owned by a person.
 
@@ -201,12 +164,9 @@ Using the Struts 2 checkbox tag, we can create a series of checkboxes,
one for e
 
 **Struts 2 Checkboxlist Tag**
 
-
-~~~~~~~
+```html
 <s:checkboxlist key="personBean.carModels" list="carModelsAvailable" />
-
-
-~~~~~~~
+```
 
 The list attributes value in the checkboxlist tag tells the Struts 2 framework which method
to call to get the possible car models. In the example application, the framework will call
the EditAction class's getCarModelsAvailable method. That method returns an Array of Strings.
For each element of the Array, the Struts 2 framework creates a checkbox (including the associated
hidden field described above).
 
@@ -214,8 +174,7 @@ The key attribute value in the checkboxlist tag tells the Struts 2 framework
whi
 
 **HTML Created By Struts 2 Checkboxlist Tag**
 
-
-~~~~~~~
+```html
 <tr>
 <td class="tdLabel">
 <label for="save_personBean_carModels" class="label">Car models owned:</label></td>
@@ -231,9 +190,7 @@ The key attribute value in the checkboxlist tag tells the Struts 2 framework
whi
 <input type="hidden" id="__multiselect_save_personBean_carModels" name="__multiselect_personBean.carModels"
value="" />
 </td>
 </tr>
-
-
-~~~~~~~
+```
 
 Summary
  There are several other Struts 2 form controls you should explore. If you need more information
about the Struts 2 form tags consult the Struts 2 documentation at [http://struts.apache.org](http://struts.apache.org).


Mime
View raw message