In this tutorial you will learn how to create Struts DynaActionForm. We will recreate our address form with Struts DynaActionForm. DynaActionForm is specialized subclass of ActionForm that allows the creation of form beans with dynamic sets of properties, without requiring the developer to create a Java class for each type of form bean. DynaActionForm eliminates the need of FormBean class and now the form bean definition can be written into the struts-config.xml file. So, it makes the FormBean declarative and this helps the programmer to reduce the development time.
In this tutorial we will recreate the add form with the help of DynaActionForm. It also shows you how you can validate use input in the action class.
Adding DynaActionForm Entry in struts-config.xml
First we will add the necessary entry in the struts-config.xml file. Add the following entry in the struts-config.xml file. The form bean is of org.apache.struts.action.DynaActionForm type. The
Adding action mapping
Add the following action mapping in the struts-config.xml file:
scope="request" validate="true" input="/pages/DynaAddress.jsp"> |
Creating Action Class
Code for action class is as follows:
package roseindia.net;
|
Creating the JSP file
We will use the Dyna Form DynaAddressForm created above in the jsp file. Here is the code of the jsp(DynaAddress.jsp) file.
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
|
Add the following line in the index.jsp to call the form.
Example shows you how to use DynaActionForm.
Building Example and Testing
To build and deploy the application go to Struts\strutstutorial directory and type ant on the command prompt. This will deploy the application. Open the browser and navigate to the DynaAddress.jsp page. Without entering anything in the form and submitting the submit button, your browser should show the following out put.
0 comments:
Post a Comment