[Buix-commits] r1010 - in lutinjaxx/trunk/jaxx-core: . src/main/java/jaxx/runtime/validator
Author: tchemit Date: 2008-10-30 22:05:12 +0000 (Thu, 30 Oct 2008) New Revision: 1010 Modified: lutinjaxx/trunk/jaxx-core/changelog lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java Log: add full PropertyChangeEvent java-bean support and a property valid : in that way Jaxx can bind on the validator changes. Modified: lutinjaxx/trunk/jaxx-core/changelog =================================================================== --- lutinjaxx/trunk/jaxx-core/changelog 2008-10-30 19:52:45 UTC (rev 1009) +++ lutinjaxx/trunk/jaxx-core/changelog 2008-10-30 22:05:12 UTC (rev 1010) @@ -1,5 +1,6 @@ ver-0-6 chemit 200811?? * 20081030 [chemit] improve BeanValidator : + - add full PropertyChangeEvent java-bean support and a property valid - when remove bean from validator, must remove errors from model - make possible to have a dynamic errorListModel in jaxx files * 20081030 [chemit] improve JAXXContext : Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java 2008-10-30 19:52:45 UTC (rev 1009) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java 2008-10-30 22:05:12 UTC (rev 1010) @@ -127,13 +127,16 @@ * </pre> * * @author poussin - * @version $Revision$ + * @author chemit + * @version 1.0 * <p/> * Last update: $Date$ - * by : $Author$ + * by : chemit */ public class BeanValidator<T> { + static public final String VALID_PROERTY = "valid"; + /** to use log facility, just put in your code: log.info(\"...\"); */ static private final Log log = LogFactory.getLog(BeanValidator.class); @@ -167,8 +170,12 @@ /** validator context */ protected ActionContext context; + /** map of conversion errors detected by this validator */ protected Map<String, String> conversionErrors; + /** state of the validator */ + protected boolean valid; + public BeanValidator() { pcs = new PropertyChangeSupport(this); validationSupport = new ValidationAwareSupport(); @@ -265,6 +272,7 @@ validationSupport.clearErrorsAndMessages(); errorListModel.addErrors(this); } + setValid(!hasErrors()); pcs.firePropertyChange("bean", oldBean, bean); } @@ -480,7 +488,26 @@ validationContext.setFieldErrors(map); } + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + public boolean isValid() { + return valid; + } + + public void setValid(boolean valid) { + boolean oldValid = this.valid; + this.valid = valid; + if (oldValid != valid) { + pcs.firePropertyChange(VALID_PROERTY, oldValid, valid); + } + } + protected class Listener implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent evt) { @@ -497,6 +524,7 @@ log.debug("launch validation from event [name:" + evt.getPropertyName() + " <old:" + oldValue + ", new:" + newValue + ">]"); } validate(); + setValid(!hasErrors()); setChanged(true); } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org