Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change 
notification.

The following page has been changed by MichaelJouravlev:
http://wiki.apache.org/struts/StrutsManualActionClasses

------------------------------------------------------------------------------
  
  == Action Classes ==
  
- The goal of an Action class is to process a request and return an 
ActionForward object. Action class can either implement a ''stateless 
service'', or can manage a logical ''web resource''.
+ The goal of an Action class is to process a request and return an 
ActionForward object. Action class can either implement a ''stateless service'' 
like "search", or can manage a logical ''web resource'' like "Customer".
  
- !ActionForward object identifies where control should be transferred to 
provide the appropriate response, and usually designates either another Action 
(see [:ActionChaining:action chaining]) or a presentation page. Struts is 
agnostic to presentation technology, so response can be generated using JSP 
file, Tile definition, Velocity template, XSLT stylesheet or using other means.
+ !ActionForward object identifies where control should be transferred to 
provide the appropriate response, and usually designates either another Action 
(see [:ActionChaining:action chaining]) or a presentation page. Struts is 
agnostic to presentation technology, so response can be generated using JSP 
file, Tile definition, Velocity template, XSLT stylesheet or other rendering 
engine.
  
  !ActionForward object represents a logical outcome of processing a request. 
By not defining a specific menu choice or a page URL it is possible to separate 
state of a resource from its visual representation.
  
- The following picture illustrates the difference between Struts and ASP.NET 
using a simple "render page" use case. In Struts this means something like 
"Process request and transfer control to appropriate location, like a JSP page 
that corresponds to current status of the Action". In ASP.NET this simply means 
"Display that page".
+ The following picture illustrates a simple "render page" use case implemented 
with Struts and ASP.NET. In Struts the requests means something like "Process 
request data and transfer control to a JSP page that corresponds to result of 
the processing". In ASP.NET the request simply means "Display the page".
  
  inline:basic_action_asp.gif
  
@@ -31, +31 @@

  
  Note that the code of the search action is not affected by this decision. In 
Struts the outcomes returned by an action are much more stable than the 
presentation locations. On contrary, in ASP.NET the outcome is simply the page 
that was requested.
  
- == Action As Service ==
- 
- Base Action class handles all incoming requests with one callback method, 
{{{execute()}}}. Two overloaded versions of this method are available. Choosing 
one or another depends on your servlet environment:
+ Action class handles all incoming requests with one callback method, 
{{{execute()}}}. Two overloaded versions of this method are available. Choosing 
one or another depends on your servlet environment:
  
  {{{public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
@@ -49, +47 @@

  
  Since the majority of teams using the framework are focused on building web 
applications, most projects will only use the "!HttpServletRequest" version. A 
non-HTTP execute() method has been provided for applications that are not 
specifically geared towards the HTTP protocol.
  
+ == Action And Web Forms ==
+ 
+ The most common use case in an interactive web application is submitting of 
HTML form. A user expects that if input data is not valid, the form would be 
redisplayed, keeping information entered by the user, and displaying relevant 
error messages.
+ 
+ This use case is so common and so important that it gave name to a certain 
web framework developed by a company from Redmond. This company spent 
significant amount of time making sure that developing for Web is as easy as 
designing a desktop application. How does Struts fare?
+ 
+ First, a brief recap of HTTP specification. HTTP defines eight request 
methods, two of these directly relate to handling of web forms. Below are 
relevant quotes from RFC 2616, abridged and slightly edited for readability:
+ 
+ '''GET:''' The GET method means retrieve whatever information is identified 
by the Request-URI. GET method SHOULD NOT have the significance of taking an 
action other than retrieval [and] ought to be considered "safe".
+ 
+ '''POST:''' The POST method is used to request the server to accept the 
entity enclosed in the request. POST is designed to allow a uniform method to  
... post a message to a bulletin board, newsgroup, mailing list ... [or] to 
provide a block of data, such as the result of submitting a form, to a 
data-handling process.
+ 
+ The HTTP specification defines a fundamental concept of web interaction in 
two distinct phases:
+  * On ''render phase'' (''output phase'', ''render response phase'') the 
browser retrieves information identified by request URI. This can be a static 
page, an output of some process or a visual representation of a resource that 
corresponds to URI.
+  * On ''input phase'' (''submit phase'', ''event phase'', ''apply request 
values phase'') the browser sends input data to an URI, usually by submitting 
an HTML form.
+ 
  == Action And Setup/Submit Pattern ==
  
- A request/response sequence of an interactive web application is typically 
composed out of two phases.
+ Two-phase request/response concept is traditionally implemented in Struts 
with setup/submit pattern:
+  * ''setup action'' (''pre-action'', ''output action'', ''render action'') 
prepares output data for display. It loads data from database, queues it into 
one or more arbitrary objects located in the request or session scope, then 
forwards to a view, usually a JSP page.
+  * ''submit action'' (''post-action'', ''input action'', ''accept action'', 
''event action'') processes input data from web form and redisplays the web 
form if errors has been found. If input does not contain errors, submit action 
updates application state and forwards to a success page. 
  
+ One of the reasons of splitting this functionality into two actions is that 
Action class uses just one {{{execute()}}} method to handle all kinds of 
requests. (Servlet has separate {{{doGet()}}} and {{{doPost()}}} methods.)
-  * On ''render phase'' (''output phase'', ''render response phase'') the 
browser requests a web resource to render itself.
-  * On ''input phase'' (''submit phase'', ''event phase'', ''apply request 
values phase'') the browser sends input data to a web resource, usually by 
submitting an HTML form.
- 
- In Struts a web resource is represented with Action or Action/!ActionForm 
combination.
- 
- These two phases correspond closely to HTTP GET and POST methods. HTTP 
specification recommends to use POST method for non-idempotent requests, like 
those that modify application state. GET method should be used for requests 
that can be safely repeated several times, like rendering a web page.
- 
- Two-phase request/response approach is traditionally implemented with 
setup/submit pattern:
-  * ''setup action'' (''pre-action'', ''output action'', ''render action'') 
prepares output data for display. It loads data from database and queues it 
into one or more arbitrary objects located in the request or session scope.
-  * ''submit action'' (''post-action'', ''input action'', ''accept action'', 
''event action'') processes input data and redisplays the same data entry form 
if errors has been found in the input. If input does not contain errors, submit 
action updates application state and forwards to a success page. 
- 
- A significant factor to adopting this pattern was the fact that Action class 
has only one {{{execute()}}} method instead of separate {{{doGet()}}} and 
{{{doPost()}}} methods that Servlet has.
  
  inline:setup_submit.gif
  

Reply via email to