19.3. The Development Process with StrutsPrefatory to creating a Struts application, you must do three basic things. First, determine what views will be displayed, especially the forms in the application, the data they will collect, and the actions that will be linked to the data collected. Second, record those decisions in an XML configuration file for the Struts controller (struts-config.xml), representing the forms and actions. Third, write the classes representing the forms and actions. It is crucial to note that different developers may tackle these tasks in a different order. If you are working from existing requirements, you would likely move straight to the XML configuration file. If application flow and data may be defined piecemeal, you might start working on some form and action classes and integrate them gradually into your configuration file. If you are a new Struts developer, you will likely find that you are constantly moving back and forth between the configuration file, your views, and your Java code; you will also find that, while reading this chapter, you will need to move back and forth between the section discussing the Struts configuration file and the other aspects of a Struts project. This tension between what belongs in the configuration file and what belongs in the other resources has motivated a number of Struts tools such as IDE plug-ins, XDoclet templates, and so forth; but, as with many frameworks, until you have experienced the pain, you won't obtain much gain from using them. Here is a sample to-do list for getting your Struts application off the ground: Steps 1-4: Determine views, actions, and flow
Step 5: Configure
Steps 6-7: Write code
Let's take a look at the sample application with this to-do list in mind and consider, in order, a view (item 1), its form data (item 2), the action that will respond to form data (item 3), and to what page the user should be directed after the form data has been processed (item 4). Items 5 and 6 will be addressed through the rest of the chapter. For item 7, compiling and building your application, see the file layout and Ant script with the code bundle. After the librarian logs in (username: librarian; password: librarian), one option is to follow the Book Administration link and change the status of individual books from checked out to checked in or vice versa. Figure 19-1 shows what the page looks like in my browser. Figure 19-1. Library administration pageFollowing our to-do list (and at the risk of being repetitive):
|