< Previous | Next >

Lesson 1.3: Create a form bean

In this lesson, you will create a form bean. A form bean is a type of Java™ bean that stores HTML form data from a submitted client request or stores input data from a Struts action link that a user clicked.

To create a form bean:

  1. Hover over the /computeDay action and click the Form bean icon.
    Shows /computeDay action with hover menu
  2. The Form bean selection window opens.
  3. Click New. The New Form-Bean wizard opens.
  4. In the Form Bean Name field, type dateData, then click Next.
    dataData form bean selection panel in wizard
  5. Click Next to skip the Choose new fields for your ActionForm class panel. This panel allows you to pull in fields, form information that your pages may already contained to create your form-bean. Since this is a new application, the pages in this project does not contain any form information yet. .
  6. On the Create new fields for your ActionForm class page, add the following fields using the Add button:
    Option Description
    Name Type
    year int
    month int
    day int
    dayOfWeek String
  7. Click Next.
  8. On the Create a mapping for your ActionForm class page in the Java package field type com.ibm.dayofweek.
  9. Click Finish.
    1. You should have and updated Form Bean Selection window.
  10. In the Form Bean Selection window, click the dateData form bean you just created, then click OK.
  11. Double click on the /computeDay action drop down character to show that this form bean is associated with the action.
    computeDay action expanded with dateData form bean
The form bean dateData is added to the computeDay node and the actual resource dateData.java is created in your Web project folder. Navigate to DayOfWeek > Struts > <default module> > Form Beans to see the file.
At the end of this lesson, the Project Explorer should resemble:
dateData file in Project explorer

Lesson checkpoint

You are able to create a dateData form bean and define the ActionForm class.

You learned:
  • To bring up the hover menu.
  • To define the parameters of the ActionForm class.
  • To locate the .java file in the Web project folder in the Project Explorer.
< Previous | Next >