Lesson 1.3: Creating and editing a form bean
Before you begin, you must complete Lesson 1.2: Editing your Web diagram.
A form bean is a type of Java bean. A form bean is an instance of
an ActionForm class subclass, which stores HTML form data from a submitted client request or stores input data from a Struts action link that a user clicked. An HTML form comprises fields in which the user can enter information.
Creating a form bean
Create a Struts form bean from the Web diagram editor:
- In the Web diagram, double-click the dateData form bean
icon.
- On the New Form Bean page, click Next.
- On the Choose new fields for your ActionForm class page, select the DayOfWeek check box.
- Click Next.
- On the Create new fields for your ActionForm class page,
click Add and specify the following fields:
| Name |
Type |
| year |
int |
| month |
int |
| day |
int |
| dayOfWeek |
String |
The Create new fields for your ActionForm class page should look like the following picture:

- Click Next.
-
On the Create a mapping for your ActionForm class page in the
Java package field type this text as the name of the Java package:
com.ibm.dayofweek
- Click Finish. Two things happen:
- A form bean is added to the Struts configuration file (struts-config.xml)
- A file named DateData.java is created in DayOfWeek\JavaSource\com\ibm\dayofweek (DayOfWeek > JavaSource > com.ibm.dayofweek in Project Explorer). The DateData.java file opens in the Java editor. In the next section, you will make changes to this file.
Tip: Creating your form beans before the JSP pages that use them eliminates the need to retype the field names when you create the JSP pages.
Editing the form bean
Edit the form bean source file and the Java resources file specifically for the
application:
- In the DateData.java file, find the line of code near the bottom of the file that reads:
ActionErrors errors = new ActionErrors();.
- Immediately after this code, insert the following code:
if (year < 1582)
{
errors.add("year",new org.apache.struts.action.ActionError("pre_gregorian"));
}
The code should look like the following image:

- Save and close the file.
- In the Project Explorer, expand JavaSource > com.ibm.dayofweek.resources, and then
double-click ApplicationResources.properties.
- In the ApplicationResources.properties file, remove the comment character (#) from the lines that begin with errors.header and errors.footer.
- Add the following code at the bottom of the file:
pre_gregorian=<li>Date is before 1582, the year the Gregorian calendar began</li>
The ApplicationResources.properties file should look like the following image:

- Save and close the file.
Now you are ready to begin Lesson 1.4: Creating an action and an action mapping.