Struts 1.1 Controller UML diagrams | Last update : 19/12/2003 | back to HOME PAGE |
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 :
- Context description of the example with the struts-config.xml file
- Struts 1.1 Controller Class Diagram of the org.apache.struts.action
- Sequence Diagram
- Links about Model View Controller model 2 pattern and the Struts implementation.
- Use my diagrams - the license to respect if you want to use the code
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.
2. Class diagrams |
Note
I have forgotten the association between the Action class and the ActionServlet. I will update the diagram after the summer ...
Application config, org.apache.struts.config package
ModuleConfigImpl contains a collection of static configuration information that describes an application module. For application initialization, struts-config.xml is parsed in order to dispatch mapping information in instances of ActionConfig, ForwardConfig and FormBeanConfig.
- Mapping management :
- 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
Example in struts-config.xml : <action path="/user" type="org.xxx.UserAction" name="userForm" scope="session">
ActionMapping extends ActionConfig and is not deprecated because of backward compatibility with version 1.02. - ForwardConfig encapsulates where the user will be sent to. Properties name and path correspond to the strut-config.xml line : <forward name="next" path="/forwardedPage.jsp" />. ActionForward extends ForwardConfig and is not deprecated because of backward compatibility with version 1.02.
- ActionConfig contains information of how specific events are mapped to Actions classes.
- ActionForm beans management :
- FormBeanConfig is a definition of ActionForm beans loaded from struts-config.xml : <form-bean name="userForm" type="org.apache.struts.action.DynaActionForm" />
- FormPropertConfig is a JavaBean representing the configuration information of a <form-property> element in struts-config.xml : <form-property name="property1" type="java.lang.String"/>
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 :
- Method processMapping selects the ActionConfig used to process the selection path for this request.
- Method processActionForm retrieves the ActionForm associated with a mapping or creates and stashes one if necessary.
- Method processPopulate populates the properties of the specified ActionForm from the request parameters included with this request.
- Method processValidate calls the validate() method of the specified ActionForm, and forwards back to the input form if there are any errors.
- Method processActionPerform asks the specified Action instance to handle the request, returns an ActionForward
The subclasses of Action are created and used by RequestProcessor. It is a wrapper around Business logic. To use Action, subclass it and overwrite the execute() method.
- Method execute processes the HTTP request, and creates the corresponding HTTP response. Returns an ActionForward instance describing where and how control should be forwarded.
- Method saveErrors saves the specified error messages keys into the appropriate request
HTML Form management
- ActionForm represents a general concept of data that is set or updated by a HTML Form. Struts will automatically set the state of the DynaActionForm using the corresponding fields from the HttpServletRequest.
- DynaActionForm is Specialized subclass of ActionForm that allows the creation of form beans with dynamic sets of properties, without requiring the developer to create a Java class for each type of form bean.
- DynaActionFormClass is used by DynaActionForm to manage its internal state.
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
3. Sequence Diagram |
- 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 :
- 1.1.1 retrieve and return the ActionForm bean associated with the mapping, creating one if necessary
- 1.1.2 populates the ActionForm bean with the input fields of the HTML form
- 1.1.3 validates the input field values and creates error messages if validation errors
- 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 :
- 2 the HelperBean
- 3 and / or from the ActionForm bean
4 Links |
- Ted Husted's Struts MVC resources page
- Model View Controller model 2 in Struts documentation
- Introduction of MVC by sun
- Presentation of Struts, MVC 2 by IBM with a detailed example
- Other presentation of Struts, with J2EE patterns
- Is it the end of Struts and and the MVC model 2 ? Read this interesting article on Java.net : Beyond MVC: A New Look at the Servlet Infrastructure.
5 Use my diagrams |
I have given all the diagrams to the Apache Software Foundation. However, if you want to use it for commercial purposes, please send me an e-mail.
Otherwise, you can use it if you add the following credits :
ClassStruts1_1.gif, SequenceStruts1_1 submitted diagrams by Jean-Michel Garnier on October 02. Based on an article by Jean-Michel Garnier in the http://rollerjm.free.fr web site. Copyright (c) 1999-2002 The Apache Software Foundation. All rights reserved.
Credits |
Author
I am an European software engineer who lives and works in London. For any comments / suggestions : send an e-mail to g a r n i e r j m @ y a h o o.f r (remove the spaces to get my e-mail, I have done that bc the sobig virus has filled my mailbox!)
Copyrights
The source is free to use and is available under the GNU GENERAL PUBLIC LICENSE.
'Dev... > 플밍 관련 자료' 카테고리의 다른 글
[펌] 오라클 힌트 사용법 (0) | 2005.02.11 |
---|---|
[펌] 오픈 소스 자바 프로젝트를 응용한 웹 어플리케이션개발 (0) | 2005.02.11 |
[펌] 회사 내에서 정리해 본 내용 (0) | 2005.02.11 |
[펌] EJB는 언제 사용해야 하는가? (0) | 2005.02.11 |
[펌] EJB 기반 프로젝트 수행 가이드] ④ (0) | 2005.02.11 |