< Previous | Next >

Lesson 3: Create a form bean

Learn how to create a form bean.

About this task

A form bean is a type of Java™ bean. The form bean stores HTML form data from a submitted client request or input data from a Struts action link that a user clicked.

To create a form bean:

  1. In the diagram, hold the mouse pointer over the /computeDay action and click Add Form Bean.
    On the hover menu of the /computeDay action, the mouse pointer is on the Add Form Bean icon.
  2. In the Form Bean Selection window, click New to open the New Form Bean wizard.
  3. In the Form Bean Name field, type dateData. Click Next.
    In the Form Bean Selection page, the dataData form bean is highlighted.
  4. Click Next to skip the next wizard page. Since your application is new, the pages in your project do not contain any form information yet. If they did, you could pull in fields for this information here.
  5. On the page to create new fields for your ActionForm class, add the following fields with the Add button, and click Next:
    Name Type
    year int
    month int
    day int
    dayOfWeek String
  6. On the page to create a mapping for your ActionForm class, in the Java package field, type com.ibm.dayofweek. Click Finish. An updated Form Bean Selection window is displayed.
  7. In the Form Bean Selection window, click the dateData form bean that you just created. Click OK.
  8. In the /computeDay node, double-click the small triangle near the lower right corner of the node. The Data compartment expands to show the dateData form bean that is associated with the node.
    The Data compartment of the /computeDay action is expanded to show the dateData form bean
Results
The dateData form bean is added to the /computeDay node, and the dateData.java file is created in your Web project folder. In the Project Explorer, navigate to the DayOfWeek\Struts\<default module>\Form Beans folder to see the file.
Example
At the end of this lesson, the Project Explorer looks like this:
The Project Explorer highlights the dateData file.

Lesson checkpoint

In this lesson, you created the dateData form bean and defined the ActionForm class.

You learned to do these tasks:
  • Bring up the hover menu.
  • Define the parameters of the ActionForm class.
  • Locate a Java file in the Web project folder in the Project Explorer.
< Previous | Next >