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:

  1. In the Web diagram, double-click the dateData form bean icon.
  2. On the New Form Bean page, click Next.
  3. On the Choose new fields for your ActionForm class page, select the DayOfWeek check box.
  4. Click Next.
  5. 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:

    List of the fields in the new form bean

  6. Click Next.
  7. 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

  8. Click Finish. Two things happen:

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:
  1. In the DateData.java file, find the line of code near the bottom of the file that reads: ActionErrors errors = new ActionErrors();.
  2. 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:

    Appearance of the code in the DateData.java file

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

    Appearance of ApplicationResources.properties file

  8. Save and close the file.

Now you are ready to begin Lesson 1.4: Creating an action and an action mapping.

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.