/** * Get a <code>Map</code> of any <code>Object</code>s returned from * validation routines. * * @return Map of objections returned by validators. */ public Map<String, Object> getResultValueMap() { Map<String, Object> results = new HashMap<String, Object>(); for (Iterator<String> i = hResults.keySet().iterator(); i.hasNext();) { String propertyKey = i.next(); ValidatorResult vr = this.getValidatorResult(propertyKey); for (Iterator<String> x = vr.getActions(); x.hasNext();) { String actionKey = x.next(); Object result = vr.getResult(actionKey); if (result != null && !(result instanceof Boolean)) { results.put(propertyKey, result); } } } return results; }
return new ValidatorResults(); ValidatorResults allResults = new ValidatorResults(); ValidatorResults results = new ValidatorResults(); while (dependencies.hasNext()) { String depend = dependencies.next(); allResults.merge(results); return allResults; allResults.merge(results);
/** * Add a the result of a validator action. * * @param field The field validated. * @param validatorName The name of the validator. * @param result The result of the validation. */ public void add(Field field, String validatorName, boolean result) { this.add(field, validatorName, result, null); }
Iterator propertyNames = results.getPropertyNames().iterator(); while(propertyNames.hasNext()) ValidatorResult result = results.getValidatorResult(property); Map actionMap = result.getActionMap(); Iterator keys = actionMap.keySet().iterator();
Map<String, ?> hResultValues = results.getResultValueMap();
/** * Performs validations based on the configured resources. * * @return The <code>Map</code> returned uses the property of the * <code>Field</code> for the key and the value is the number of error the * field had. * @throws ValidatorException If an error occurs during validation */ public ValidatorResults validate() throws ValidatorException { Locale locale = (Locale) this.getParameterValue(LOCALE_PARAM); if (locale == null) { locale = Locale.getDefault(); } this.setParameter(VALIDATOR_PARAM, this); Form form = this.resources.getForm(locale, this.formName); if (form != null) { this.setParameter(FORM_PARAM, form); return form.validate( this.parameters, this.resources.getValidatorActions(), this.page, this.fieldName); } return new ValidatorResults(); }
public void testOnlyReturnErrors() throws ValidatorException { // property name of the method we are validating String property = "date"; // name of ValidatorAction String action = "date"; ValidatorResources resources = setupDateResources(property, action); TestBean bean = new TestBean(); bean.setDate("2/3/1999"); Validator validator = new Validator(resources, "testForm"); validator.setParameter(Validator.BEAN_PARAM, bean); ValidatorResults results = validator.validate(); assertNotNull(results); // Field passed and should be in results assertTrue(results.getPropertyNames().contains(property)); // Field passed but should not be in results validator.setOnlyReturnErrors(true); results = validator.validate(); assertFalse(results.getPropertyNames().contains(property)); }
Iterator propertyNames = results.getPropertyNames().iterator(); while(propertyNames.hasNext()) ValidatorResult result = results.getValidatorResult(property); Map actionMap = result.getActionMap(); Iterator keys = actionMap.keySet().iterator();
Map<String, ?> hResultValues = results.getResultValueMap();
/** * Performs validations based on the configured resources. * * @return The <code>Map</code> returned uses the property of the * <code>Field</code> for the key and the value is the number of error the * field had. * @throws ValidatorException If an error occurs during validation */ public ValidatorResults validate() throws ValidatorException { Locale locale = (Locale) this.getParameterValue(LOCALE_PARAM); if (locale == null) { locale = Locale.getDefault(); } this.setParameter(VALIDATOR_PARAM, this); Form form = this.resources.getForm(locale, this.formName); if (form != null) { this.setParameter(FORM_PARAM, form); return form.validate( this.parameters, this.resources.getValidatorActions(), this.page, this.fieldName); } return new ValidatorResults(); }
public void testOnlyValidateField() throws ValidatorException { // property name of the method we are validating String property = "date"; // name of ValidatorAction String action = "date"; ValidatorResources resources = setupDateResources(property, action); TestBean bean = new TestBean(); bean.setDate("2/3/1999"); Validator validator = new Validator(resources, "testForm", property); validator.setParameter(Validator.BEAN_PARAM, bean); ValidatorResults results = validator.validate(); assertNotNull(results); // Field passed and should be in results assertTrue(results.getPropertyNames().contains(property)); }
/** * Add a the result of a validator action. * * @param field The field validated. * @param validatorName The name of the validator. * @param result The result of the validation. * @param value The value returned by the validator. */ public void add( Field field, String validatorName, boolean result, Object value) { ValidatorResult validatorResult = this.getValidatorResult(field.getKey()); if (validatorResult == null) { validatorResult = new ValidatorResult(field); this.hResults.put(field.getKey(), validatorResult); } validatorResult.add(validatorName, result, value); }
Iterator propertyNames = results.getPropertyNames().iterator(); results.getValidatorResult(propertyName);
ValidatorResults results = new ValidatorResults(); params.put(Validator.VALIDATOR_RESULTS_PARAM, results); results.merge(field.validate(params, actions)); results.merge(field.validate(params, actions));
/** * Returns a <code>Map</code> of values returned * from any validation that returns a value other than * <code>null</code> or <code>Boolean</code> with the * key the full property path of the field. * @return Returns a <code>Map</code> of values, otherwise returns null if no results. */ public Map getResultValueMap() { return (validatorResults != null ? validatorResults.getResultValueMap() : null); }
/** * Performs validations based on the configured resources. * * @return The <code>Map</code> returned uses the property of the * <code>Field</code> for the key and the value is the number of error the * field had. * @throws ValidatorException If an error occurs during validation */ @GwtIncompatible("incompatible method") public ValidatorResults validate() throws ValidatorException { Locale locale = (Locale) this.getParameterValue(LOCALE_PARAM); if (locale == null) { locale = Locale.getDefault(); } this.setParameter(VALIDATOR_PARAM, this); Form form = this.resources.getForm(locale, this.formName); if (form != null) { this.setParameter(FORM_PARAM, form); return form.validate( this.parameters, this.resources.getValidatorActions(), this.page, this.fieldName); } return new ValidatorResults(); }
/** * Check a validator has not been run for a field and the result. */ private void checkNotRun(ValidatorResults results, String field, String action) { ValidatorResult result = results.getValidatorResult(field); assertNotNull(field + " result", result); assertFalse(field + "[" + action + "] run", result.containsAction(action)); // System.out.println(field + "[" + action + "] not run"); }
return new ValidatorResults(); ValidatorResults allResults = new ValidatorResults(); ValidatorResults results = new ValidatorResults(); while (dependencies.hasNext()) { String depend = (String) dependencies.next(); allResults.merge(results); return allResults; allResults.merge(results);
/** * Add a the result of a validator action. * * @param field The field validated. * @param validatorName The name of the validator. * @param result The result of the validation. */ public void add(Field field, String validatorName, boolean result) { this.add(field, validatorName, result, null); }