Creating dynaforms

A dynaform, or dynamic form bean, is an instance of a subclass org.apache.struts.action.DynaActionForm. You can specify the fields of a dynaform in the Struts configuration file, rather than in the ActionForm class.

For a generic form bean, create both the form-bean class and a form-bean entry in the Struts configuration file. To create a dynaform, add a form-bean entry in the Struts configuration file; the type of this entry should be org.apache.struts.action.DynaActionForm or one of its subclasses. Then add additional form-property entries that represent the fields in your configuration file. At run time, a form bean will be created dynamically.

To create a dynaform:

  1. In Enterprise Explorer of the Web perspective, right-click the name of a Struts project or a resource in a Struts project.

  2. On the pop-up menu, click

    New | Other | Web | Struts | ActionForm Class | Next.

  3. On the New ActionForm Class page in the

    ActionForm class name field, type the name of the ActionForm subclass that you are creating.

  4. In the Superclass field, type org.apache.struts.action.DynaActionForm.

  5. Fill out the other fields as appropriate for the subclass you are creating, and click Next.

  6. On the

    Create new fields for your ActionForm class page, click

    Add and type the name and type of each field that you want to create.

    • If you want to accept the default values, click Finish. A form-bean entry is added to the Struts configuration file.

    • If you want to change the default values, click Next.

  7. On the

    Create a mapping for your ActionForm class page:

    • If you want to create a form bean mapping, be sure that the

      Add new mapping check box is selected, and that the names of the configuration file and the mapping are correct.

    • If you do not want to create a form bean mapping, clear the

      Add new mapping check box.

  8. Click Finish