We learned in this tutorial about creating a basic web application in Struts, We had used Struts Frameworks ActionForm to manage the form data. Let us see how to use DynaActionForm to manage the form data.
DynaActionForm is also called as Dynamic Form Bean. These are extensions of Form Beans that allow you to specify their properties inside the struts configuration file instead of having to create a concrete class.
To create a DynaActionForm, we have to make following entry in struts-config.xml file.
While using ActionForm, we create an entry in struts-config.xml with <form-bean> tag. We specify the class name of ActionForm class.
In case of DynaActionForm, we create a dynamic form bean by specifying properties in struts-config.xml itself. In above code snippet we have created a login form with two properties: username and password. We have also provided its initial values.
Once you have define an entry for Form bean in struts-config.xml, you can use this form in any of your action using normal <action> tag.
Hence when the login action will be called, the form data will be populated in DynaActionForm and bean object will be passed to execute() method of LoginAction.
To fetch the form data from Form object use get() method of DynaActionForm class.