CustomValidatorRulespublic class CustomValidatorRules extends Object
Methods Summary |
---|
public static boolean | validateMinChoose(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionMessages errors, javax.servlet.http.HttpServletRequest request)
try {
Object[] values = (Object[]) PropertyUtils.getProperty(bean, field.getProperty());
int min = Integer.parseInt(field.getVarValue("minChoose"));
if (values == null || values.length < min) {
errors.add(field.getKey(),
Resources.getActionMessage(request, va, field));
return false;
}
} catch (Exception e) {
// silently ignore
}
return true;
| public static boolean | validateTwoFields(java.lang.Object bean, org.apache.commons.validator.ValidatorAction va, org.apache.commons.validator.Field field, org.apache.struts.action.ActionErrors errors, javax.servlet.http.HttpServletRequest request)
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)) {
errors.add(
field.getKey(),
Resources.getActionError(request, va, field));
return false;
}
} catch (Exception e) {
errors.add(
field.getKey(),
Resources.getActionError(request, va, field));
return false;
}
}
return true;
|
|