You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by Apache Wiki <wi...@apache.org> on 2007/02/10 23:50:03 UTC

[Struts Wiki] Update of "StrutsManualActionClasses" by MichaelJouravlev

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

The comment on the change is:
Removed HTTP spec portion

------------------------------------------------------------------------------
  The goal of an Action class is to either implement a stateless ''service'' like "Search", or to manage a stateful ''business object'' like "Customer".
  
- An Action class handles a request and returns an !ActionForward object, which represents a logical outcome of processing a request. An action mapping in {{{struts-config.xml}}} file associates !ActionForward object with another Action (see [:ActionChaining:action chaining]), or with a presentation page or with any arbitrary URL.  By not defining a specific menu choice or a page URL in Java code it is possible to separate logical state of a ''web resource'' from its visual representation.
+ An Action class handles a request and returns an !ActionForward object, which represents a logical outcome of processing a request. An action mapping in {{{struts-config.xml}}} file associates !ActionForward object with either another Action (see [:ActionChaining:action chaining]), or with a presentation page, or with any arbitrary URL.  By not defining a specific target location in Java code, it is possible to separate logical outcome of an action from its visual representation.
  
  Struts is agnostic to presentation technology, so response can be generated using JSP file, Tile definition, Velocity template, XSLT stylesheet or other rendering engine.
  
- 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:
+ 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:
  
  {{{public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
@@ -20, +20 @@

                               HttpServletResponse response)
                      throws Exception;}}}
  
- 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.
+ 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.
  
  == Using Action To Display A Web Page ==
  
- JSP is a default view technology used when developing with Struts. JSP file creates dynamic web content by reading information from various Java beans floating around in page, request, session or application scope. In a Model 1 application these beans are put into scope by the code that resides in JSP page itself.
+ JSP is default view technology used when developing with Struts. JSP file creates dynamic web content by reading information from various Java objects stored in page, request, session or application scope. In a Model 1 application these objects are stored in a scope by the code that resides in JSP page itself.
  
- A standard practice to display a dynamic page in a Struts application is to use Action class "in front" of a JSP page. Action class creates needed beans, puts them in an appropriate context, and forwards control to a JSP page that reads information from these beans and displays it. Action class has access to all contexts available to JSP page except !PageContext.
+ A standard practice to display a dynamic page in a Struts application is to use Action class "in front" of a JSP page (see [http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html Model 2 web application architecture]). Action class creates needed beans, puts them in an appropriate context, and forwards control to a JSP page that reads information from these beans and displays it. Action class has access to all standard J2EE contexts except JSP-specific page context.
+ 
+ As a concequence of Model 2 architecture, JSP pages are not directly navigated with browser when programming with Struts. Applications developed with Struts or with other similar web frameworks like !WebWork or Stripes are often called ''action-based''. This is different from so called ''page-based'' frameworks like ASP.NET, where web page is accessed directly from browser. In ASP.NET a web page usually delegates events processing and page lifecycle-related tasks to a code-behind class.
  
  The following picture illustrates a "render page" use case implemented with Struts and ASP.NET.
  
  inline:basic_action_asp.gif
  
- == Action And Web Forms ==
+ == Action And Setup/Submit Pattern ==
  
  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 then the form is redisplayed keeping information entered by the user, and displaying relevant error messages. 
  
- To explain how this use case is handled in Struts let us turn to HTTP specification. HTTP defines eight request methods, two of which are directly related to 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 above definitions explain fundamental concepts of web interaction. They define input/output as a process consisting of two phases. It is important that both phases are initiated by browser.
- 
-  * 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 ==
- 
- Two-phase input/output process is traditionally implemented in Struts with setup/submit pattern:
+ This input/output process 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.