FileDocCategorySizeDatePackage
CustomValidatorRules.javaAPI DocExample2200Tue Aug 10 01:00:36 BST 2004com.oreilly.strutsckbk.ch08

CustomValidatorRules

public class CustomValidatorRules extends Object

Fields Summary
Constructors Summary
Methods Summary
public static booleanvalidateMinChoose(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 booleanvalidateTwoFields(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;