List of usage examples for org.apache.commons.validator Field getArg
public Arg getArg(int position)
Arg
object at the given position. From source file:org.hyperic.util.validator.common.CommonValidatorUtil.java
/** * Validates a password verification field which requires that the * value exactly match the String value of the bean property * referenced by property argument 1 (probably "password"). * * @param bean containing the fields to validate. * @param Field object containing the property resource info. * /*from w w w .ja va 2 s .co m*/ */ public static boolean validatePasswordVerification(Object bean, Field field) { boolean valid = false; String pwdv = ValidatorUtils.getValueAsString(bean, field.getProperty()); String pwd = ValidatorUtils.getValueAsString(bean, field.getArg(1).getKey()); // compare the pw verification field to the pw field. if ((pwd != null && pwdv != null) && (pwdv.compareTo(pwd) == 0)) valid = true; return valid; }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Add an error to the Errors object/*from w w w . j a v a2 s . com*/ * * @param va * Validator action * @param errors * Errors object to populate * @param field * The field to use when creating the Error * @param validatorErrorValue1 * First error value to use * @param validatorErrorValue2 * Second error value to use */ protected static void addError(ValidatorAction va, Errors errors, Field field, Object validatorErrorValue1, Object validatorErrorValue2) { Arg arg = field.getArg(0); String validatorKey = va.getMsg(); if (arg != null) { String fieldMsgKey = arg.getKey(); if (fieldMsgKey != null) { Error fieldMsg = ErrorFactory.createError(fieldMsgKey); Error validateError = ErrorFactory.createError(validatorKey, fieldMsg, validatorErrorValue1, validatorErrorValue2); errors.add(validateError); } } }
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. * // www .j av a2 s .c o 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; }