Академический Документы
Профессиональный Документы
Культура Документы
Introduction
The goal of this article is to illustrate the Struts 1.1 Controller with UML diagrams. This
article is an introduction to the Struts framework in order to help beginners
programmers to understand the MVC model 2.
Contents :
To print the figures of this article, configure your printer in landscape mode.
back to Top
1. Context description
In order to show how to use the Struts framework classes, I have designed some
diagrams starting from a simple example : a client submits a form to a "forwarded"
page :
struts-config.xml
This is the configuration resource file - which is parsed by the Struts Controller for
initialization.
back to Top
2. Class diagrams
Note
I have forgotten the association between the Action class and the ActionServlet. I will
update the diagram after the summer ...
• Mapping management :
o ActionConfig contains information of how specific events are mapped to
Actions classes.
path is a request URI path used to select this mapping. Example
in the jsp page : <form name="myForm" method="post"
action="/user.do">
type is the Action class name which can handle the event
name is the name of the form bean, if any, associated with the
action.
scope is the JSP scope (application, session, request, page) within
which the form bean will be created
The parsing is done by using the famous jakarta Digester, which is a powerful
component of XML - java objects mapping.
Struts Controller
The ActionServlet class is the core of the framework. It is an HTTPServlet which receives
requests from the browser and forwards it depending on a configuration file : struts-
config.xml.
• Since Struts 1.1, the processing logic has been delegated to the
RequestProcessor class :
o Method processMapping selects the ActionConfig used to process the
selection path for this request.
o Method processActionForm retrieves the ActionForm associated with a
mapping or creates and stashes one if necessary.
o Method processPopulate populates the properties of the specified
ActionForm from the request parameters included with this request.
o Method processValidate calls the validate() method of the specified
ActionForm, and forwards back to the input form if there are any errors.
o Method processActionPerform asks the specified Action instance to handle
the request, returns an ActionForward
Nb : You can still define your own ActionForm in the Struts 1.02 way, by sub-class
ActionForm.
User classes
• HelperBean is a "Helper" class, it is a value object bean which holds the data
required by the screens.
• UserAction is a typical Action, inherits the Struts Action class.
• UserDelegate is based on the Business Delegate pattern. This is an intermediate
class which decouples business components from the code that uses them,
encapsulates business services and access to the Model. See the Struts User's
guide to understand what a Model is in the MVC model 2 pattern.
forwardedPage.jsp is not a class, it is the targeted jsp page. represents the View in the
Model view Controller model 2 pattern.
Error management
• ActionMessages is a collection of ActionMessage
• ActionMessage encapsulates an user message, contains a message key for I18N
management (Internationalization) and 4 objects for parametric replacement in
the message text)
• ActionErrors extends ActionMessages is a collection of ActionError
• ActionError encapsulates error messages
back to Top
3. Sequence Diagram
Messages Description
• 1 the client submits an HTML form, doPost method is called to allow the the
HtppServlet ActionServlet to handle the POST request
• 1.1 The Struts Controller ActionServlet delegates to RequestProcessor the process
of the request
• RequestProcessor does the following actions :
o 1.1.1 retrieve and return the ActionForm bean associated with the
mapping, creating one if necessary
o 1.1.2 populates the ActionForm bean with the input fields of the HTML
form
o 1.1.3 validates the input field values and creates error messages if
validation errors
o 1.1.4 acquires an UserAction instance to process the request, calling the
overwritten execute method of UserAction
1.1.4.1 retrieves data from the UserActionForm bean by
getProperties methods
1.1.4.2 calls business services through the BusinessDelegate
1.1.4.3 populates a value object bean (optional)
1.1.4.4 forwards to the specified destination in struts-config.xml
• The forwarded page retrieves data from :
o 2 the HelperBean
o 3 and / or from the ActionForm bean