TechnoBuzz

A Techno Blog, mainly about Java

Struts2 Trainings

One of the struts 2 sample applications is the Mailreader application which has training course via Struts from Square One site .

Building Web Applications
Building Struts 2 Applications [ Welcome] [More …]

Struts 2 components

Action Handler, Result Handler, Custom Tags

Interceptor : bring custom code into call stack

  • Timer Interceptor
  • Prepare (able) – If the Action implements Preparable, calls its prepare method.

value stack : stack of objects that expression language can pull from

  • Action instance pushed onto stack

Jumpstarting JUnit (More …)

Capturing Input(More …)

Validating Input (More …)

Request Lifecycle in Struts 2 applications

  • User Sends request: User sends a request to the server for some resource.
  • FilterDispatcher determines the appropriate action: The FilterDispatcher looks at the request and then determines the appropriate Action.
  • Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request.
  • Execution of Action: Then the action method is executed to perform the database related operations like storing or retrieving the data from database.
  • Output rendering: Then the Result render the output.
  • Return of Request: Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing.

Display the result to user: Finally the control is returned to the servlet container, which sends the output to the user browser.
Struts 2 Big Picture

The diagram depicts the architecture of Struts 2 Framework. It shows the the initial request goes to the Servlet container, which is then passed through a standard filer chain.

  1. ActionContextCleanUp filter: The ActionContextCleanUp filter is optional. It is useful when integrating other technologies such as SiteMesh Plugin.
  2. FilterDispatcher: the required FilterDispatcher is called, which in turn consults the ActionMapper to determine if the request should invoke an action. If the ActionMapper determines that an Action should be invoked, the FilterDispatcher delegates control to the ActionProxy.
  3. ActionProxy: The ActionProxy consults the Configuration Files manager, which is initialized via the struts.xml file. Then the ActionProxy creates an ActionInvocation, which implements the command pattern. The ActionInvocation process invokes the Interceptors (if configured) and then invokes the action.
  4. Once the Action returns, the ActionInvocation is responsible for looking up the proper result associated with the Action result code mapped in struts.xml. The result is then executed, which often (but not always, as is the case for Action Chaining) involves a template written in JSP or FreeMarker to be rendered. While rendering, the templates can use the Struts Tags provided by the framework. Some of those components will work with the ActionMapper to render proper URLs for additional requests.
  5. Then the Interceptors are executed again in reverse order. Finally the response returns through the filters configured in web.xml file.
  6. If the ActionContextCleanUp filter is configured, the FilterDispatcher does not clean the ThreadLocal ActionContext. If the ActionContextCleanUp filter is not present then the FilterDispatcher will cleanup all the ThreadLocals present.

Resources

If you install the war on an application server (like tomcat ) you can easily run the sample projtect. Here is the struts 201 slides

Th version I have of the application mentions: “For more about the MailReader, including alternate implementations and a set of formal Use Cases, please visit the Struts University MailReader site” .

The full source code for MailReader is available as svn site, binaries, nightlies

Other Struts2 Trainings include Migrating to Struts2 the and JPA .

REFERENCES:

December 2, 2007 Posted by | AJAX, Struts | 1 Comment