Struts 1.3 Configuring different set of validations for the same ActionForm
Joined: Mar 13, 2005
Hi I am using Struts 1.3. I would like to use declarative validations for the action forms. I have a JSP with two buttons - Save, Back. When i click on Save button, i would like to trigger the following validations :required, integer, intRange etc. And when i click on Back button, i wudnt want to use the 'required' validation. But i would still need the other validations like integer, intRange etc. Would it be possible to configure such type of validations in the validation xml? I browsed thru the struts validator manual, but couldnt find anything to relate to this kind of scenario. I contemplated using 'validWhen', but realized that it was meant for a different purpose.
I guess one of the options would be to not use the declarative validation and use the validate method in the ActionForms to differentiate between click of Save and Back buttons(with request parameters).
If you have any thoughts or suggestions, please let me know.Thanks.
Karthik <br />SCJP 1.4 SCWCD 1.4 SCBCD 1.3
Joined: Feb 15, 2005
One option would be to have your ActionForm extend ValidatorActionForm instead of ValidatorForm. You would then specify the action path as the name in your validation.xml file instead of the form name. This allows you to specify two different sets of validations for the same ActionForm. For more information see the Struts Javadoc for the above classes.