Hi!
I was looking for this kind of functionality some time
ago and didn't find any standard way of doing reusable
validators.
What I did was more like a hack, but it worked:
1. For server side validation.
Overwrite validate() method of FormBean class with
something like this:
public ActionErrors validate(ActionMapping
mapping,HttpServletRequest request) {
ServletContext application =
getServlet().getServletContext();
ActionErrors errors = new ActionErrors();
String validationKey = "validationNameIn
Validation.xml";
Validator validator =
Resources.initValidator(validationKey,this,application,
request,errors, page);
try {validatorResults = validator.validate();}
catch (ValidatorException e) {
logger.error(e.getMessage(), e);
}
return errors;
}
Just change validationKey to whatever is in your
validation.xml.
2. Client-side validation.
Put the following code at the top of your page:
<script type="text/javascript">
var
realFormName_required=formNameFromValidationXMLFile_required;
</script>
Again replace "realFormName" with the form name how it
appears in your struts-config.xml. And replace
"formNameFromValidationXMLFile" to the validator name
(should be the same one you used for server-side
validation).
Hope this will help.
Cheers,
Leo
> Quinn Stone wrote:
> > Is there any way to define the validation for a
> common form field once in
> > validation.xml and re-use the validation in other
> <form> blocks?
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]