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()));
}
}