ru refering to ActionForm or Action class ?
If you want to use Validator framework along with DynaActionForm Class and the senario which you have given Action class could be regardless of what you need therefore you can any type of action class.
you need to use DynaValidatorActionForm Class instead of DynaActionForm class.
Check out the below notes which could be informative.
You can choose when creating your Form Bean is to define a Dynamic Form Bean in the struts-config.xml file, as shown here:
<form-beans>
<form-bean name="logonForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="username" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
</form-bean>
</form-beans>
Dynamic Form Beans do not require you to create concrete Form Bean objects; instead, you define the properties that your Form Bean should have and their types, and Struts will dynamically create the Form Bean for you. Validator allows you to use this concept just as you would with core Struts. The only difference for Validator is that you specify that your Form Bean is of type org.apache.struts.validator.DynaValidatorForm instead of org.apache.struts.action.DynaActionForm.
Identical to the way concrete Form Beans work with Validator, the logical name given to Dynamic Form Beans is the name that you will use when defining validations in the validation.xml file. Validator uses the matching names to tie the validations to the Form Bean.
In addition to the two standard options for creating Form Beans, Validator provides an advanced feature for tying multiple validation definitions to one Form Bean definition. When using ValidatorForm- or DynaValidatorForm-based Form Beans, Validator uses the logical name for the Form Bean from the struts-config.xml file to map the Form Bean to validation definitions in the validation.xml file. This mechanism is ideal for most cases; however, there are scenarios where Form Beans are shared among multiple actions. One action may use all the Form Bean's fields and another action may use only a subset of the fields. Because validation definitions are tied to the Form Bean, the action that uses only a subset of the fields has no way of bypassing validations for the unused fields. When the Form Bean is validated, it will generate error messages for the unused fields because Validator has no way of knowing not to validate the unused fields; it simply sees them as missing or invalid.
To solve this problem, Validator provides two additional ActionForm subclasses that allow you to tie validations to actions instead of Form Beans. That way you can specify which validations to apply to the Form Bean based on which action is using the Form Bean. For concrete Form Beans, you subclass org.apache.struts.validator.ValidatorActionForm, as shown here:
public class AddressForm extends ValidatorActionForm {
?}
For Dynamic Form Beans, you specify a type of org.apache.struts.validator.DynaValidatorActionForm for your Form Bean definition in the struts-config.xml file:
<form-bean name="addressForm"
type="org.apache.struts.validator.DynaValidatorActionForm">
?</form-bean>
Inside your validation.xml file, you map a set of validations to an action path instead of a Form Bean name, because if you have two actions defined, Create Address and Edit Address, which use the same Form Bean, as shown here, each has a unique action path:
<action-mappings>
<action path="/createAddress"
type="com.jamesholmes.minihr.CreateAddressAction"
name="addressForm"/>
<action path="/editAddress"
type="com.jamesholmes.minihr.EditAddressAction"
name="addressForm"/>
</action-mappings>
The following validation.xml file snippet shows two sets of validations that are intended for the same Form Bean, but are distinguished by different action paths:
<formset>
<form name="/createAddress">
<field property="city" depends="required">
<arg0 key="prompt.city"/>
</field>
</form>
<form name="/editAddress">
<field property="state" depends="required">
<arg0 key="prompt.state"/>
</field>
</form>
</formset>
Because your Form Bean subclasses either ValidatorActionForm or DynaValidatorActionForm, Validator knows to use an action path to find validations instead of the Form Bean's logical name.
REFERENCE : Struts, The Comeplete reference - by James Holmes
REGARDS,
RaHuL
>i dont understand u r saying there is no need for a bean just configuring in struts-config.xml is enough then y again a bean
Guess you need bit of clarity on struts and validator framework.
Just letme know without defining specfic form bean / ActionForm class how is that you gonna use validator framework ?
Please try something similar to one metioned down below hope that makes it much clear.
if you are using a typical Action class here is how you read the attributes.
<!-- Configuring Form Beans -->
<form-bean name="LoginForm" type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="username" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
<form-property name="userBean" type="com.login.UserBean"/>
</form-bean>
<!-- Configuring Action paths -->
<action path="/login"type="com.login.LoginAction"name="LoginForm" scope="session">
<forward name="success" path="/Dashboard.jsp" />
<forward name="failure" path="/login.jsp" />
</action>
validator.xml settings
<form-validation>
<formset>
<form name="LoginForm">
<field property="username" depends="required">
<arg0 key="prompt.username"/>
</field>
<field property="password" depends="required">
<arg0 key="prompt.password"/>
</field>
</form>
</formset>
</form-validation>
Action Class:
public class LoginAction extends Action{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
DynaValidatorForm dform =(DynaValidatorForm)form;
String username = form.get("username");
String password = form.get("password");
UserBean userBeanInstance = new UserBean();
// calling model
-
-
-
-
dform.set("userBean",userBeanInstance);
return mapping.findForward("success");
}
}
hope this might help :)
REGARDS,
RaHuL