Apache Struts Web Application Framework
|
How to Build Applications | Contributors: |
About This Document |
This document outlines one possible sequence of development steps that can be followed to create a
Struts application. It is not intended as a complete description of each
referenced development activity. More detailed documentation is available
elsewhere and is referenced by "(more...)" links where possible.
|
Caveats |
- Requirements development and design are outside of the scope of this document.
- For help installing Struts, see the Getting Started chapter.
- There are many other ways to approach Struts development and there are many
other features available besides the ones discussed below. This document
outlines only one way to get started.
- This document focuses on form/data centric applications, but may also work with
other types of applications.
- This material was written for Struts 1.1 (beta 2).
|
Overview |
- Implement data entry forms as JSP files.
- Implement one or more
ActionForm descendents to buffer data
between JSPs and Actions.
- Create an XML document that defines the validation rules for your
application.
- Implement one or more
Action descendents to respond form
submissions.
- Create
struts-config.xml to associate forms with
actions.
- Create or update
web.xml to reference
ActionServlet , taglibs used by Struts.
- Parallel Tasks
- Building
- Unit Testing
- Deployment
|
Details |
- Implement data entry forms as JSP files.
- Use elements from the
html taglib to define the form
elements. (more...)
- Use
message and other elements from the
bean taglib to define the labels and other static text
of the form. (more...)
- Create and maintain a properties file of the text elements to be
displayed. (more...)
- Use
property attributes to link form fields to
ActionForm instance variables.
- Implement one or more
ActionForm descendents to buffer data
between JSPs and Actions.
- Create get/set pairs that correspond to the property names in your
related JSP form. Example:
<html:text property="city" />
needs:
getCity() and setCity(String c)
- When needed, create a
reset method that sets the fields of the
ActionForm to their default values. Most ActionForms do
not need to do this.
- Create an XML document that defines the validation rules for your
application.
- Implement one or more
Action descendents to respond to form
submissions.
- Descend from DispatchAction or LookupDispatchAction if you want one class
to handle more than one kind of event (example: one Action to handle
'insert', 'update' and 'delete' events, using a different "surrogate"
execute method for each).
(more...)
- Use the
execute method (or its surrogates) of your
Action class to interface with objects in your application responsible
for database interaction, such as EJBs, etc.
- Use the return value of the
execute method (or its surrogates)
direct the user interface to the appropriate next page.
- Create
struts-config.xml to associate forms with
actions. The file minimally needs:
<form-beans> section to relate form-beans with ActionForms
(more...)
<action-mappings> section to relate <html:form>
actions with Action classes (more...)
<message-resources> to make your ApplicationResources
available to the rest of the app
<plug-in> section to link in the Struts validator and other extensions
(more...)
- Create or update
web.xml to reference
ActionServlet , taglibs used by Struts.
(more...)
- Parallel Tasks
- Building
- Use Ant. It can compile, create WAR file, perform XSLT
transformations, run unit tests, interact with version control
systems, clean up, etc.
(more...)
- Create and use build script incrementally, as you create files
that need to be copied, compiled, etc.
- Unit Testing
- Unit test normal java beans with JUnit.
(more...)
- Unit test JSP, taglibs and conventional servlet components with
Cactus. (more...)
- Unit test Action servlets with StrutsTestCase.
(more...)
- Add all unit tests to the build script as a separate target.
This target should use the
junit tag to launch each
TestCase descendent. (more...)
- Deployment
- Build script should create a war file containing the files developed
above, along with files that make up the Struts framework.
|
|