In this tutorial you will see how the DynaActionForm eliminates the
need to create a seperate ActionForm for each Action class and allows
you to easily define the Form object in the xml declaration file.
DynaActionForm Beans are the extension of Form Beans that allows you to specify the form properties inside the struts configuration file instead of creating a seperate concreate class. It will become tedious to create a seperate form bean for each action class.
Using DynaActionForm we can easily create Form Bean in struts-config.xml file. The struts-config.xml file entry for the DyanActionForm Bean is shown below.
We need to typecast the form object to DynaActionForm object in the execute method of the action class. After that we can access the Form Bean properties. We will consider a simple login application for our example. Here we will check the user name and password, if they are equal then we will forward the user to the success page, else we will forward the user to the failue page.
Now we will run the Login application. Lets enter the user name as "tutorials4u" and the password as "tutorials4u" and click the Login button.
You can download the source code of this example by clicking on the Download link below.