Learn how to create a form bean.
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:
- In the diagram, hold the mouse pointer over the /computeDay action
and click Add Form Bean.
- In the Form Bean Selection window, click New to
open the New Form Bean wizard.
- In the Form Bean Name field, type dateData.
Click Next.
- 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.
- 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 |
- 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.
- In the Form Bean Selection window, click the
dateData form bean that you just created. Click OK.
- 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 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.
At the end of this lesson, the Project Explorer looks like this: