Package es.internna.spring.annotations.validation

Examples of es.internna.spring.annotations.validation.StringConstraint


            errors.rejectValue(field.getName(), errorCodes[0]);
    }
   
    protected void validateFieldAsString(Field field, Object object, Errors errors)
    {
        StringConstraint req = field.getAnnotation(StringConstraint.class);
        if (req.required() && validateNull(field, object)) errors.rejectValue(field.getName(), errorCodes[0]);
        String stringField = null;
        try
        {
            field.setAccessible(true);
            stringField = field.get(object).toString();
        }
        catch (Exception ex)
        {
            if (log.isDebugEnabled()) log.debug("Error validating " + field, ex);
        }
        if ((stringField != null) & (req.regexp().length() > 0))
        {
            try
            {
                Pattern pattern = Pattern.compile(req.regexp());
                Matcher matcher = pattern.matcher(stringField);
                if (!matcher.matches())
                    errors.rejectValue(field.getName(), errorCodes[1], req.regexp());
            }
            catch (Exception ex)
            {
                if (log.isDebugEnabled()) log.debug("Error validating " + field, ex);
            }
        }
        if ((stringField != null) & (req.maxLength() > 0))
        {
            if (stringField.length() > req.maxLength())
                errors.rejectValue(field.getName(), errorCodes[3], Integer.toString(req.maxLength()));
        }
    }
View Full Code Here

TOP

Related Classes of es.internna.spring.annotations.validation.StringConstraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.