











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












**
Advanced Features
Create a new validation method
Modify the validation-rules.xml file to rules. xml
contain the new validation method
Modify the validation.xml file to use the new
validation rule rule.
Create a new validation method
public static boolean validateExactLength( Object bean, ValidatorAction va, Field field, ActionErrors errors,
HttpServletRequest request) {
String value = null;
if (isString( bean)) {
value = (String) bean;
} else {
value = ValidatorUtil. getValueAsString( bean, field. getProperty());
String exactLength = field. getVarValue(" exactlength");
if (! GenericValidator. isBlankOrNull( value)) {
try {
int length = Integer. parseInt( exactLength);
if ( value. length() != length ) {
errors. add( field. getKey(), Resources. getActionError( request, va, field));
return false;
} catch (Exception e) { errors. add( field. getKey(), Resources. getActionError( request, va, field));
return false;
} return true;
Modify validation.xml
** exactlength**
** 10 **
** mask**
^[ a- zA- Z]$*
Best Practice Guidelines
Advaced Validation
Techniques
QUIZ