- Hello World! Application Requirements
- Applying the Model-View-Controller Pattern
- The View Component: The HTML Form and the Form Bean
- MessageResources and Application.properties Files
- The Struts Form Bean: HelloForm.java
- Data Validation and ActionErrors
- The Controller Component: HelloAction.java
- The Model Component (HelloModel.java)
- Passing Data to the View Using Attributes: Constants.java
- Tying It All Together: The struts-config.xml File
MessageResources and Application.properties Files
The hello.jsp file uses the <bean:messages> tag to display a banner title and data entry prompt. Listing 3.2 presents the file where the actual text is stored.
Listing 3.2 The Application.properties File for Hello World!
; Application Resources for the "Hello" sample application ; ; Update History: ; ; Date Whom Action ; ======== ==== ====== ; 06/01/02 kmb Creation ; ; Application Resources that are specific to the hello.jsp file hello.jsp.title=Hello - A first Struts program hello.jsp.page.heading=Hello World! A first Struts application hello.jsp.prompt.person=Please enter a name to say hello to : ; Validation and error messages for HelloForm.java and HelloAction.java ch03.hello.dont.talk.to.atilla=I told you not to talk to Atilla!!! ch03.hello.no.person.error=Please enter a <i>PERSON</i> to say hello to!
You can see that some of the properties are used in the hello.jsp file, but others are accessed from Java classes as well. Comments have been added for organization.
Also, the properties themselves have been named in a way that makes them easier to manage. For example, all properties accessed from the hello.jsp file follow the naming pattern hello.jsp.foo.bar. When you have a large application with numerous tags, this makes understanding the file much easier.