Search in sources :

Example 6 with ConstraintException

use of grails.validation.exceptions.ConstraintException in project grails-core by grails.

the class ConstrainedProperty method setEmail.

/**
     * @param email The email to set.
     */
public void setEmail(boolean email) {
    if (!isValidStringType()) {
        throw new ConstraintException("Email constraint can only be applied to String properties");
    }
    Constraint c = appliedConstraints.get(EMAIL_CONSTRAINT);
    if (email) {
        if (c == null) {
            c = new EmailConstraint();
            c.setOwningClass(owningClass);
            c.setPropertyName(propertyName);
            appliedConstraints.put(EMAIL_CONSTRAINT, c);
        }
        c.setParameter(true);
    } else {
        if (c != null) {
            appliedConstraints.remove(EMAIL_CONSTRAINT);
        }
    }
}
Also used : EmailConstraint(org.grails.validation.EmailConstraint) MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) MinConstraint(org.grails.validation.MinConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) BlankConstraint(org.grails.validation.BlankConstraint) RangeConstraint(org.grails.validation.RangeConstraint) ValidatorConstraint(org.grails.validation.ValidatorConstraint) ScaleConstraint(org.grails.validation.ScaleConstraint) NullableConstraint(org.grails.validation.NullableConstraint) MaxConstraint(org.grails.validation.MaxConstraint) CreditCardConstraint(org.grails.validation.CreditCardConstraint) UrlConstraint(org.grails.validation.UrlConstraint) InListConstraint(org.grails.validation.InListConstraint) MatchesConstraint(org.grails.validation.MatchesConstraint) NotEqualConstraint(org.grails.validation.NotEqualConstraint) EmailConstraint(org.grails.validation.EmailConstraint) ConstraintException(grails.validation.exceptions.ConstraintException)

Aggregations

ConstraintException (grails.validation.exceptions.ConstraintException)6 BlankConstraint (org.grails.validation.BlankConstraint)6 CreditCardConstraint (org.grails.validation.CreditCardConstraint)6 EmailConstraint (org.grails.validation.EmailConstraint)6 InListConstraint (org.grails.validation.InListConstraint)6 MatchesConstraint (org.grails.validation.MatchesConstraint)6 MaxConstraint (org.grails.validation.MaxConstraint)6 MaxSizeConstraint (org.grails.validation.MaxSizeConstraint)6 MinConstraint (org.grails.validation.MinConstraint)6 MinSizeConstraint (org.grails.validation.MinSizeConstraint)6 NotEqualConstraint (org.grails.validation.NotEqualConstraint)6 NullableConstraint (org.grails.validation.NullableConstraint)6 RangeConstraint (org.grails.validation.RangeConstraint)6 ScaleConstraint (org.grails.validation.ScaleConstraint)6 SizeConstraint (org.grails.validation.SizeConstraint)6 UrlConstraint (org.grails.validation.UrlConstraint)6 ValidatorConstraint (org.grails.validation.ValidatorConstraint)6 MissingPropertyException (groovy.lang.MissingPropertyException)1