List of usage examples for org.apache.commons.validator GenericValidator maxLength
public static boolean maxLength(String value, int max)
Checks if the value's length is less than or equal to the max.
From source file:org.sgrp.singer.validator.ArrayFieldChecks.java
/** * Checks if the field's length is less than or equal to the maximum value. * A <code>Null</code> will be considered an error. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being performed. * @param field The <code>Field</code> object associated with the current * field being validated.//from w w w. j ava 2s .co m * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. * @return True if stated conditions met. */ public static boolean validateMaxLength(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { String[] value = null; if (isStringArray(bean)) { value = (String[]) bean; } else { value = new String[0]; } for (int i = 0; i < value.length; i++) { if (value[i] != null) { try { int max = Integer.parseInt(field.getVarValue("maxlength")); if (!GenericValidator.maxLength(value[i], max)) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } catch (Exception e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } } return true; }
From source file:org.springmodules.commons.validator.FieldChecks.java
/** * Checks if the field's length is less than or equal to the maximum value. * A <code>Null</code> will be considered an error. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed./* www .j a v a 2 s. co m*/ * @param field The <code>Field</code> object associated with the current * field being validated. * @param errors The <code>Errors</code> object to add errors to if any * validation errors occur. * -param request * Current request object. * @return True if stated conditions met. */ public static boolean validateMaxLength(Object bean, ValidatorAction va, Field field, Errors errors) { String value = extractValue(bean, field); if (value != null) { try { int max = Integer.parseInt(field.getVarValue("maxlength")); if (!GenericValidator.maxLength(value, max)) { rejectValue(errors, field, va); return false; } } catch (Exception e) { rejectValue(errors, field, va); return false; } } return true; }
From source file:org.springmodules.validation.commons.FieldChecks.java
/** * Checks if the field's length is less than or equal to the maximum value. * A <code>Null</code> will be considered an error. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed.//from ww w. ja v a2s. c o m * @param field The <code>Field</code> object associated with the current * field being validated. * @param errors The <code>Errors</code> object to add errors to if any * validation errors occur. * -param request * Current request object. * @return True if stated conditions met. */ public static boolean validateMaxLength(Object bean, ValidatorAction va, Field field, Errors errors) { String value = FieldChecks.extractValue(bean, field); if (value != null) { try { int max = Integer.parseInt(field.getVarValue("maxlength")); if (!GenericValidator.maxLength(value, max)) { FieldChecks.rejectValue(errors, field, va); return false; } } catch (Exception e) { FieldChecks.rejectValue(errors, field, va); return false; } } return true; }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.EctValidation.java
public boolean maxLength(int iMax, String inputValue) { boolean validation = true; org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator(); if (iMax != 0) { if (!GenericValidator.maxLength(inputValue, iMax)) { validation = false;//w w w.j av a 2s. c om } } return validation; }