Most of the validators extend DefaultValidator.  The method
doAssertValidity() is to be overridden in subclasses to preform
additional validation.  Here is the code for assertValidity() from the
DefaultValidator class:

    /**
     * Determine whether a testValue meets the criteria specified
     * in the constraints defined for this validator
     *
     * @param testValue a <code>String</code> to be tested
     * @exception ValidationException containing an error message if the
     * testValue did not pass the validation tests.
     */
    public void assertValidity(String testValue)
            throws ValidationException
    {
        message = null;

        if ((!required && minLength == 0)
                && (testValue == null || testValue.length() == 0))
        {
            return;
        }
        else if (required
                && (testValue == null || testValue.length() == 0))
        {
            message = requiredMessage;
            throw new ValidationException(requiredMessage);
        }

        // allow subclasses first chance at validation
        doAssertValidity(testValue);

        if (maskPattern != null)
        {
            boolean patternMatch =
                    patternMatcher.matches(testValue, maskPattern);

            log.debug("Trying to match " + testValue
                    + " to pattern " + maskString);

            if (!patternMatch)
            {
                message = maskMessage;
                throw new ValidationException(maskMessage);
            }
        }

        if (minLength > 0 && testValue.length() < minLength)
        {
            message = minLengthMessage;
            throw new ValidationException(minLengthMessage);
        }
        if (maxLength > 0 && testValue.length() > maxLength)
        {
            message = maxLengthMessage;
            throw new ValidationException(maxLengthMessage);
        }
    }


Notice that doAssertValidity is called after testing the required rule
bute before any other others.  Is there a reason for this?  It seems
that it might be better for the basic forms of validation to occur
before the subclass begins its validation.

Thoughts?

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to