r1206 - jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator
Author: tchemit Date: 2009-02-04 20:16:34 +0000 (Wed, 04 Feb 2009) New Revision: 1206 Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java Log: when remove bean from validator when transfert errors to fields Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java =================================================================== --- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java 2009-02-04 20:16:04 UTC (rev 1205) +++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/BeanValidator.java 2009-02-04 20:16:34 UTC (rev 1206) @@ -25,6 +25,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -33,23 +34,6 @@ /** @author chemit */ public class BeanValidator<B> { - /** - * Pour definir le niveau de validation. - * <p/> - * Par défaut, le validateur est supposé géré des erreurs, mais on peut aussi l'utiliser - * pour consigner des warnings sur le bean surveiller. - */ - public enum Scope { - ERROR, - WARNING - } - - public enum State { - VALID, - CONVERSION_ERROR, - FAILED - } - /** la nom de la propriété bean */ static public final String BEAN_PROERTY = "bean"; @@ -78,11 +62,17 @@ protected boolean changed = false; /** state of the validator (is true if no errors of error scope is found) */ - protected boolean valid; + protected boolean valid = true; /** bean to be watched */ protected B bean = null; + /** + * map of fields by scope + * TODO use this and remove fields property and xworks patch :) + */ + protected EnumMap<ValidatorScope, List<ValidatorField<B>>> fieldsByScope; + /** list of fields watched by this validator */ protected List<ValidatorField<B>> fields; @@ -231,7 +221,9 @@ if (bean == null) { // must remove all errors from this validator on errorListModel validationSupport.clearErrorsAndMessages(); - //errors.clear(); + + // dispatch in each field the new errors + dispatchErrorsToFields(); } else { try { Method method = this.bean.getClass().getMethod("addPropertyChangeListener", PropertyChangeListener.class); @@ -254,7 +246,7 @@ // so dettach bean, must rebuild the fields setBean(null); initFields(); - //pcs.firePropertyChange(CONTEXT_NAME_PROPERTY, oldValidationContextName, contextName); + pcs.firePropertyChange(CONTEXT_NAME_PROPERTY, oldValidationContextName, contextName); } public void setParentValidator(BeanValidator<?> parentValidator) { @@ -298,6 +290,7 @@ * @param valueClass the type of converted value * @return the converted value, or null if conversion was not ok */ + @SuppressWarnings({"unchecked"}) public <T> T convert(String fieldName, String value, Class<T> valueClass) { if (fieldName == null) { throw new IllegalArgumentException("fieldName can not be null"); @@ -419,6 +412,7 @@ * <p/> * The previously filed errors of a given field where a conversion error occurs will be removed. */ + @SuppressWarnings({"unchecked"}) protected void transfertConversionErrorsToFieldErrors() { Map map = validationContext.getFieldErrors(); for (Entry<String, String> entry : conversionErrors.entrySet()) {
participants (1)
-
tchemit@users.labs.libre-entreprise.org