List of usage examples for org.apache.commons.validator Field getProperty
public String getProperty()
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate that a value falls within a specified float range. * /*www . j a v a 2 s .c o m*/ * @param bean * The event containing the field to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return True if the value is a float, and falls within the range * specified in the rules file. */ public static boolean validateFloatRange(Object bean, ValidatorAction va, Errors errors, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return validateFloatRange(value, va, errors, field); }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate that a value falls within a specified double range. * /*from ww w. j a va 2 s. c o m*/ * @param bean * The event containing the field to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return True if the value is a double, and falls within the range * specified in the rules file. */ public static boolean validateDoubleRange(Object bean, ValidatorAction va, Errors errors, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return validateDoubleRange(value, va, errors, field); }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate a value as a credit card number. * //w ww. j a va 2 s . c om * @param bean * The event containing the field to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return Formatted credit card value, or null if validation fails. */ public static Long validateCreditCard(Object bean, ValidatorAction va, Errors errors, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return validateCreditCard(value, va, errors, field); }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate that a value contains at least a certain number of characters. * // w w w. ja va 2s.com * @param bean * The event containing the field to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return True if the value is at least the minimum length. */ public static boolean validateMinLength(Object bean, ValidatorAction va, Errors errors, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return validateMinLength(value, va, errors, field); }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate that a value contains at most a certain number of characters. * // w w w .ja v a2s. co m * @param bean * The event containing the field to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return True if the value is at most the maximum length. */ public static boolean validateMaxLength(Object bean, ValidatorAction va, Errors errors, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return validateMaxLength(value, va, errors, field); }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate the contents of two fields to verify that they match. This is * useful for comparing a password and a confirmation value, for instance. * //from w w w. j a v a 2 s. co m * @param bean * The event containing the fields to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The first field to validate * @return True if the first field is null, or if the first and second * fields contain identical values. */ public static boolean validateTwoFields(Object bean, ValidatorAction va, Errors errors, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = field.getVarValue("secondProperty"); //$NON-NLS-1$ String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { try { if (!value.equals(value2)) { Arg arg = field.getArg(1); Error fieldMsg = null; if (arg != null) { String fieldMsgKey = arg.getKey(); if (fieldMsgKey != null) { fieldMsg = ErrorFactory.createError(fieldMsgKey); } } addError(va, errors, field, fieldMsg); return false; } } catch (Exception e) { addError(va, errors, field, null); return false; } } return true; }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate a value that is required if a certain circumstance is met. * //from www.j a v a 2 s . com * @param bean * The event containing the field to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return True if validation passes */ public static boolean validateRequiredIf(Object bean, ValidatorAction va, Errors errors, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); boolean required = false; int i = 0; String fieldJoin = "AND"; //$NON-NLS-1$ if (!GenericValidator.isBlankOrNull(field.getVarValue("fieldJoin"))) { //$NON-NLS-1$ fieldJoin = field.getVarValue("fieldJoin"); //$NON-NLS-1$ } if (fieldJoin.equalsIgnoreCase("AND")) { //$NON-NLS-1$ required = true; } while (!GenericValidator.isBlankOrNull(field.getVarValue("field[" + i //$NON-NLS-1$ + "]"))) { //$NON-NLS-1$ String dependProp = field.getVarValue("field[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$ String dependTest = field.getVarValue("fieldTest[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$ String dependTestValue = field.getVarValue("fieldValue[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$ String dependIndexed = field.getVarValue("fieldIndexed[" + i + "]"); //$NON-NLS-1$ //$NON-NLS-2$ if (dependIndexed == null) { dependIndexed = "false"; //$NON-NLS-1$ } String dependVal = null; boolean thisRequired = false; if (field.isIndexed() && dependIndexed.equalsIgnoreCase("true")) { //$NON-NLS-1$ String key = field.getKey(); if ((key.indexOf("[") > -1) && (key.indexOf("]") > -1)) { //$NON-NLS-1$ //$NON-NLS-2$ String ind = key.substring(0, key.indexOf(".") + 1); //$NON-NLS-1$ dependProp = ind + dependProp; } } dependVal = ValidatorUtils.getValueAsString(bean, dependProp); if (dependTest.equals(FIELD_TEST_NULL)) { if ((dependVal != null) && (dependVal.length() > 0)) { thisRequired = false; } else { thisRequired = true; } } if (dependTest.equals(FIELD_TEST_NOTNULL)) { if ((dependVal != null) && (dependVal.length() > 0)) { thisRequired = true; } else { thisRequired = false; } } if (dependTest.equals(FIELD_TEST_EQUAL)) { thisRequired = dependTestValue.equalsIgnoreCase(dependVal); } if (fieldJoin.equalsIgnoreCase("AND")) { //$NON-NLS-1$ required = required && thisRequired; } else { required = required || thisRequired; } i++; } if (required) { if (GenericValidator.isBlankOrNull(value)) { addError(va, errors, field, null); return false; } return true; } return true; }
From source file:org.openmobster.core.common.validation.CoreValidator.java
/** * Checks if the field is required./* ww w . j a va2 s. c o m*/ * * @return boolean If the field isn't <code>null</code> and * has a length greater than zero, <code>true</code> is returned. * Otherwise <code>false</code>. */ public static boolean validateRequired(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return !GenericValidator.isBlankOrNull(value); }
From source file:org.openmobster.core.common.validation.CoreValidator.java
/** * /* w w w . ja va 2 s. co m*/ * @param bean * @param field * @return */ public static boolean minimumLength(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String varValue = field.getVarValue("minimumLength"); return GenericValidator.minLength(value, Integer.parseInt(varValue)); }
From source file:org.openmrs.contrib.metadatarepository.webapp.util.ValidationUtil.java
/** * Validates that two fields match./*from ww w. j a v a2 s. com*/ * @param bean * @param va * @param field * @param errors */ public static boolean validateTwoFields(Object bean, ValidatorAction va, Field field, Errors errors) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = field.getVarValue("secondProperty"); String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { try { if (!value.equals(value2)) { FieldChecks.rejectValue(errors, field, va); return false; } } catch (Exception e) { FieldChecks.rejectValue(errors, field, va); return false; } } return true; }