|
In struts, every form control need to have one ActionForm class property and getter/setter method for it. DynaActionForm will replace the ActionForm with the simple xml mappings so that the java form class can be eliminated and thus helps in developing the application more quickly. The advantages of using the DynaActionForm are as follows:-
- No ActionForm is required.
- Replace the property mapping with the simple xml file so that if any property is to add and remove then there is no need to compile the java class again.
The mapping is to be done in the struts-config.xml file in the <form-bean> tag for all the form properties.
<form-bean name="inputForm" type="org.apache.struts.action.DynaActionForm" > <form-property name="name" type="java.lang.String"/> <form-property name="email" type="java.lang.String" /> </form-bean>
Data Types :- The types supported by DynaActionForm include:
- java.math.BigDecimal
- java.math.BigInteger
- boolean and java.lang.Boolean
- byte and java.lang.Byte
- char and java.lang.Character
- java.lang.Class
- double and java.lang.Double
- float and java.lang.Float
- int and java.lang.Integer
- long and java.lang.Long
- short and java.lang.Short
- java.lang.String
- java.sql.Date
- java.sql.Time
- java.sql.Timestamp
Example For DynaActionForm :-
(1) Struts-config.xml file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <!-- ================================================ Form Bean Definitions --> <form-beans> <form-bean name="inputForm" type="org.apache.struts.action.DynaActionForm" > <form-property name="name" type="java.lang.String"/> <form-property name="email" type="java.lang.String" /> </form-bean> </form-beans> <!-- ========================================= Global Exception Definitions --> <global-exceptions></global-exceptions> <!-- =========================================== Global Forward Definitions --> <global-forwards></global-forwards> <!-- =========================================== Action Mapping Definitions --> <action-mappings> <action path="/dynaActionExample" type="com.visualbuilder.DynaActionFormExample" name="inputForm" input="/index.jsp" /> </action-mappings> <!-- ======================================== Message Resources Definitions --> <message-resources parameter="MessageResources" /> </struts-config>
|