struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sdu...@apache.org
Subject [2/3] struts-site git commit: updated coding-actions page
Date Mon, 24 Apr 2017 19:15:58 GMT
updated coding-actions 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/8aea28ac
Tree: http://git-wip-us.apache.org/repos/asf/struts-site/tree/8aea28ac
Diff: http://git-wip-us.apache.org/repos/asf/struts-site/diff/8aea28ac

Branch: refs/heads/master
Commit: 8aea28ac88518599dc00afa455e9ab1711c05acc
Parents: 04b8881
Author: Stefaan Dutry <stefaan.dutry@gmail.com>
Authored: Mon Apr 24 21:12:52 2017 +0200
Committer: Stefaan Dutry <stefaan.dutry@gmail.com>
Committed: Mon Apr 24 21:12:52 2017 +0200

----------------------------------------------------------------------
 source/getting-started/coding-actions.md | 40 +++++++++++++--------------
 1 file changed, 20 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts-site/blob/8aea28ac/source/getting-started/coding-actions.md
----------------------------------------------------------------------
diff --git a/source/getting-started/coding-actions.md b/source/getting-started/coding-actions.md
index 5b0fddc..d85296c 100644
--- a/source/getting-started/coding-actions.md
+++ b/source/getting-started/coding-actions.md
@@ -4,9 +4,9 @@ title: Coding actions
 ---
 ## Coding actions
 
-This tutorial assumes you've completed the [Using Struts 2 Tags](#PAGE_14811875) tutorial
and have a working using_tags project. The example code for this tutorial, coding_action,
is available for checkout from the Struts 2 GitHub repository: [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples).
+This tutorial assumes you've completed the [Using Struts 2 Tags](using-tags.html) tutorial
and have a working using-tags project. The example code for this tutorial, coding-actions,
is available for checkout from the Struts 2 GitHub repository: [https://github.com/apache/struts-examples](https://github.com/apache/struts-examples).
 
-__Introduction__
+### Introduction
 
 Coding a Struts 2 Action involves several parts:
 
@@ -14,7 +14,7 @@ Coding a Struts 2 Action involves several parts:
 2. Mapping a result to a view
 3. Writing the controller logic in the Action class
 
-In the previous tutorials we covered how to configure Struts to map a URL such as hello.action
to a Action class such as HelloWorldAction (specifically the execute method).
+In the previous tutorials we covered how to configure Struts to map a URL such as `hello.action`
to an Action class such as `HelloWorldAction` (specifically the execute method).
 
 **Action Mapping**
 
@@ -24,19 +24,19 @@ In the previous tutorials we covered how to configure Struts to map a
URL such a
 </action>
 ```
 
-The Action mapping above also specified that if the execute method of class HelloWorldAction
returns success then the view HelloWorld.jsp will be returned to the browser.
+The Action mapping above also specified that if the `execute` method of class `HelloWorldAction`
returns `success` then the view `HelloWorld.jsp` will be returned to the browser.
 
 This tutorial will introduce you to the basics of writing the controller logic in the Action
class.
 
-__Struts 2 Action Classes__
+### Struts 2 Action Classes
 
 Action classes act as the controller in the MVC pattern. Action classes respond to a user
action, execute business logic (or call upon other classes to do that), and then return a
result that tells Struts what view to render.
 
 Struts 2 Action classes usually extend the `ActionSupport` class, which is provided by the
Struts 2 framework. Class `ActionSupport` provides default implementations for the most common
actions (e.g. execute, input) and also implements several useful Struts 2 interfaces. When
your Action class extends class `ActionSupport` your class can either override the default
implementations or inherit them.
 
-If you examine class HelloWorldAction from tutorial [Using Struts 2 Tags](using-tags.html)
you'll see that it extends class `ActionSupport` and then overrides method execute.
+If you examine class HelloWorldAction from tutorial [Using Struts 2 Tags](using-tags.html)
you'll see that it extends the class `ActionSupport` and then overrides method `execute`.
 
-In method execute is where we placed what we want this controller to do in response to the
hello.action.
+The method `execute` is where we placed what we want this controller to do in response to
the `hello.action`.
 
 **Method execute of HelloWorldAction**
 
@@ -51,11 +51,11 @@ public String execute() throws Exception {
 ```
 > Note that method execute declares it throws an Exception. We'll cover in a later tutorial
how to configure Struts to handle any Exceptions thrown from the Action classes methods.
 
-__Processing Form Input In The Action Class__
+### Processing Form Input In The Action Class
 
-One of the most common responsibilities of the Action class is to process user input on a
form and then make the result of the processing available to the view page. To illustrate
this responsibility, let's say that on our view page, HelloWorld.jsp, we want to display a
personal hello, such as "Hello Struts User Bruce."
+One of the most common responsibilities of the Action class is to process user input on a
form and then make the result of the processing available to the view page. To illustrate
this responsibility, let's say that on our view page, `HelloWorld.jsp`, we want to display
a personal hello, such as "Hello Struts User Bruce."
 
-In the [Using Struts 2 Tags](using-tags.html) example application we added a Struts 2 form
to index.jsp.
+In the [Using Struts 2 Tags](using-tags.html) example application we added a Struts 2 form
to `index.jsp`.
 
 **Struts 2 Form Tags**
 
@@ -66,11 +66,11 @@ In the [Using Struts 2 Tags](using-tags.html) example application we added
a Str
 </s:form>
 ```
 
-Make a note of the value of the name attribute for the Struts 2 textfield tag, which is userName.
When the user clicks on the submit button for the above form, the action hello will be executed
(hello.action). The form field values will be posted to the Struts 2 Action class (HelloWorldAction).
The Action class may automatically receive those form field values provided it has a public
set method that matches the form field name value.
+Make a note of the value of the name attribute for the Struts 2 textfield tag, which is userName.
When the user clicks on the submit button for the above form, the action hello will be executed
(`hello.action`). The form field values will be posted to the Struts 2 Action class (`HelloWorldAction`).
The Action class may automatically receive those form field values provided it has a public
set method that matches the form field name value.
 
 So for the HelloWorldAction class to automatically receive the userName value it must have
a public method setUserName (note the JavaBean convention discussed in tutorial [Hello World](hello-world-using-struts2.html)).
 
-For the example application associated with this tutorial add the following Java code to
class HelloWorldAction.
+For the example application associated with this tutorial, add the following Java code to
class `HelloWorldAction`.
 
 **Add userName to HelloWorldAction**
 
@@ -96,21 +96,21 @@ if (userName != null) {
 }
 ```
 
-Now build and deploy the application. Enter your name in the form and click the submit button.
You should see the following page.
+Now build and run (`mvn jetty:run`) the application. Enter your name in the form and click
the submit button. You should see the following page.
 
-![personalhello.png](attachments/att14974998_personalhello.png)
+![coding_actions_form_submit_result.png](attachments/coding_actions_form_submit_result.png)
 
-When the form is submitted, Struts will call any set methods of the HelloWorldAction class
that match the form field names. So in this example method setUserName was called and passed
the value the user entered in the userName form field.
+When the form is submitted, Struts will call any set methods of the HelloWorldAction class
that match the form field names. So in this example method `setUserName` was called and passed
the value the user entered in the `userName` form field.
 
-On the index.jsp we also have a Struts 2 action link (see tutorial [Using Struts 2 Tags](using-tags.html))
that includes a query string parameter: userName=Bruce+Phillips. If you click on that link
you should see the result of:
+On the `index.jsp` we also have a Struts 2 action link (see tutorial [Using Struts 2 Tags](using-tags.html))
that includes a query string parameter: `userName=Bruce+Phillips`. If you click on that link
you should see the following result:
 
-![hellobruce.png](attachments/att14974997_hellobruce.png)
+![coding_actions_link_with_param_result.png](attachments/coding_actions_link_with_param_result.png)
 
-Since the query string parameter is userName, Struts passed the value of that parameter to
the setUserName method.
+Since the query string parameter is `userName`, Struts passed the value of that parameter
to the `setUserName` method.
 
-On the view page, HelloWorld.jsp, you can also access the userName value by using the Struts
2 property tag (see tutorial [Using Struts 2 Tags](using-tags.html)). Try showing just the
userName value on the view page.
+On the view page, `HelloWorld.jsp`, you can also access the `userName` value by using the
Struts 2 property tag (see tutorial [Using Struts 2 Tags](using-tags.html)). Try showing just
the `userName` value on the view page.
 
-__Summary__
+### Summary
 
 This tutorial introduced you to how to code the Action class so it can process user input
on a form or values in a query string parameter. If the form had numerous fields, it would
be cumbersome to have a set method that matches up with each form field. So our next tutorial
will cover how to integrate a model class, form fields in the view and form processing in
the Action class.
 


Mime
View raw message