Recall the above example how flow goes?
->initialization
->RequestProcessing
->processPath()
->If action is located, check is performed whether there are any form processings.
How ?
- If name attribute is configured in the <action> tag, then Performs form processing inside the behavior named processActionForm().
- Here check is performed whether the formbean instance is available in the specified scope or not.
- If form bean instance is available then calls reset() and resets the form bean instance. Then invokes the setXXX() and sets the new data into the form bean instance and places in its specified scope.
- If the form bean instance is not available in the specified scope, creates a new form bean instance calls setXXX() and places the instance in the specified scope
- After performing the above form processing as the validate attribute is true by default, validates the form fields if the validate(-,-) returns an empty ActionError or null, the request is given to Action. If the validate(-,-) returns ActionErrors object then displays the error messages in the same jsp page.
- Once the request goes to the Action the remaining steps are same as 1st application.
In the 2 & 3 examples we used form beans and identified its use, now in the application development we find an issue if number of formbean classes are written as it requires huge active memory space.
So here we wanted to reduce writing formbean classes.
How to overcome this?
The Struts framework supports the above requirement by providing us a Declarative Formbean or ready made formbean named
org.apache.struts.DynaActionForm (a subtype of org.apache.struts.action.ActionForm).
How to use DynaActionForm with respect to Application development.
Step A):
^^^^^^^
Configure the DynaActionForm in the struts-config file using form beans tag.
Specify the form properties using the <form-property> tag a child tag to <form-bean>
<form-bean name="mybean" type="org.apache.struts.action.DynaActionForm">
<form-property name="uname" type="java.lang.String"/>
<form-property name="pass" type="java.lang.String"/>
</form-bean>
Step B)
^^^^^^^
Associating the DynaActionForm to the Action is same as we associated ActionForm with Action i.e using name attribute value.
Step C)
^^^^^^^
Retrieve the DynaActionForm bean in our Action
DynaActionForm daf=(DynaActionForm)af;
//use Object.get(<property>) behavior
vo.setUname((String)daf.get("uname"));
vo.setPass((String)daf.get("pass"));
Directory struture as shown in previous example.
***Delete the previous LoginActionForm.java
Next requirement:-
How to validate DynaActionForm fields.
As DynaActionForm is configured Declaratively we have to validate its fields or properties also in a Declarative fashion.
To support Declarative validations in struts we commence our learning with Validation Framework.
- How to plug validation framework with struts framework?
- What validation framework provides?
- how to use validation framework for Action form bean and DynaActionForm beans?



