Home

 

Creating a Struts form bean

In the previous section, we created the logon action. The logon action is invoked when the customer enters a customer ID (social security number). This information is passed to the action as a Struts form bean.

To create and associate the logonForm form bean to the logon action, do these steps:

Hover with the mouse over the /logon action, then click the Add Form Bean icon () from the selections presented.

In the Form Bean Selection dialog, do these steps:

Click New.
In the New Form Bean dialog , type LogonForm as the Form Bean Name.
Click Form Bean Type to launch the New ActionForm Class dialog.
In the New ActionForm Class dialog, accept the defaults for package, modifiers, superclass, and method stubs. Accept the generated name LogonForm for the ActionForm class name. Click Next.
In the Create new fields for your ActionForm class dialog, click Add to create a field named ssn of type String. Click Finish.
At this time the Form Bean Type field contains the value rad75strutsweb.forms.LogonForm. Accept the values for the New Form-Bean dialog. Click Finish.
The logonForm bean is added to the Form Bean Selection dialog. Click OK.

A LogonForm class is created in the rad75strutsweb.forms package and the Struts configuration file is updated.

Figure | -8 shows the creation of the form bean and the result in the Web Diagram.

Figure 15-8 Struts components: Adding a Struts form bean

ibm.com/redbooks