Struts 1 - How to Build Applications

##### Struts 1

- Welcome
- Learning
- Roadmap
- Releases

##### Documentation

- User Guide
- FAQs and HOWTOs
- Release Notes
- Javadoc
- DTDDoc

##### Support

- User Mailing List
- Issue Tracker (JIRA)
- Wiki Pages

##### Components

- Struts Apps
- Struts EL
- Struts Extras
- Struts Faces
- Struts Scripting
- Struts Taglib
- Struts Tiles

##### Project Documentation

- Project Information
- Project Reports

## How to Build Applications

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.

For those who are short on time and/or patience, you can get a Struts application up and running in a matter of minutes thanks to Maven's archetype feature.

NOTE - as of the time of this writing (10/16/2006), the specified version in this example has not been released. Once this has been released, this note can be removed and the archetype will work fine. ``

                    	   $ cd ~/projects

    					   $ mvn archetype:create                                \
    					         -DarchetypeGroupId=org.apache.struts            \
    					         -DarchetypeArtifactId=struts-archetype-blank    \
    					         -DarchetypeVersion=1.3.5                        \
    					         -DgroupId=com.example                           \
    					         -DpackageName=com.example.projectname           \
    					         -DartifactId=my-webapp

                    	   $ cd my-webapp

                    	   $ mvn install

                    	   $ mvn jetty:run

### Caveats

1. Requirements development and design are outside of the scope of this document.
2. For help installing the framework, see the Getting Started chapter.
3. There are many other ways to approach development with the framework and there are many other features available besides the ones discussed below. This document outlines only one way to get started.
4. This document focuses on form/data centric applications, but may also work with other types of applications.
5. This material was originally written for Struts 1.1 (beta 2), and reviewed for the 1.3.5 distribution.

### Overview

1. Implement data entry forms as JSP files.
2. Implement one or more `ActionForm` descendents to buffer data between JSPs and Actions.
3. Create an XML document that defines the validation rules for your application.
4. Implement one or more `Action` descendents to respond form submissions.
5. Create `struts-config.xml` to associate forms with actions.
6. Create or update `web.xml` to reference `ActionServlet.`
7. Parallel Tasks
   1. Building
   2. Unit Testing
   3. Deployment

### Details

1. Implement data entry forms as JSP files.
   1. Use elements from the `html` taglib to define the form elements. (more...)
   2. Use `message` and other elements from the `bean` taglib to define the labels and other static text of the form. (more...)
      1. Create and maintain a properties file of the text elements to be displayed. (more...)
   3. Use `property` attributes to link form fields to `ActionForm` instance variables.
2. Implement one or more `ActionForm` descendents to buffer data between JSPs and Actions.
   1. 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)

   2. 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.
3. Create an XML document that defines the validation rules for your application.
4. Implement one or more `Action` descendents to respond to form submissions.
   1. 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...)
   2. 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.
   3. Use the return value of the `execute` method (or its surrogates) direct the user interface to the appropriate next page.
5. Create `struts-config.xml` to associate forms with actions. The file minimally needs:
6. Create or update `web.xml` to reference `ActionServlet` (more...)
7. Parallel Tasks
   1. Building
      1. Use Ant. It can compile, create WAR file, perform XSLT transformations, run unit tests, interact with version control systems, clean up, etc. (more...)
      2. Create and use build script incrementally, as you create files that need to be copied, compiled, etc.
   2. Unit Testing
      1. Unit test normal JavaBeans with JUnit. (more...)
      2. Unit test JSP, taglibs, and conventional servlet components with Cactus. (more...)
      3. Unit test Action servlets with StrutsTestCase. (more...)
      4. 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...)
   3. Deployment
      1. Build script should create a WAR file containing the files developed above, along with files that make up the framework.