]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged #2817 to 6.0: AbstractField.isValid() and AbstractField.validate() were incons...
authorHenri Sara <henri.sara@itmill.com>
Wed, 8 Apr 2009 13:08:02 +0000 (13:08 +0000)
committerHenri Sara <henri.sara@itmill.com>
Wed, 8 Apr 2009 13:08:02 +0000 (13:08 +0000)
svn changeset:7369/svn branch:6.0

src/com/itmill/toolkit/data/Validator.java
src/com/itmill/toolkit/demo/sampler/features/commons/ValidationExample.java
src/com/itmill/toolkit/ui/AbstractField.java

index 0e09e3de6bae15d073477fac715da20cc642ec9f..d0094914eda6060e6745dde19c2224bac6a0bba6 100644 (file)
@@ -17,6 +17,9 @@ import com.itmill.toolkit.terminal.PaintTarget;
  * {@link Validator.InvalidValueException} if the given value is not valid by
  * its standards.
  * 
+ * Validators should not have side effects on other objects as they can be
+ * called from Paintable.paint().
+ * 
  * @author IT Mill Ltd.
  * @version
  * @VERSION@
index 75bacd5b103fe40959372314e1a1649b1a1166d1..19444045a985dcf83b92281c345dda56bc5380e8 100644 (file)
@@ -46,17 +46,15 @@ public class ValidationExample extends VerticalLayout {
                     throw new Validator.InvalidValueException("Username "
                             + value + " already in use");
                 }
-                usernames.add(value);
             }
         });
         username.addListener(new ValueChangeListener() {
             public void valueChange(ValueChangeEvent event) {
                 TextField tf = (TextField) event.getProperty();
                 tf.validate();
-                if (tf.isValid()) {
-                    addComponent(new Label("Added " + tf.getValue()
-                            + " to usernames"));
-                }
+                usernames.add(tf.getValue());
+                addComponent(new Label("Added " + tf.getValue()
+                        + " to usernames"));
             }
         });
 
index c998236f321e54a225e6abc923de7b6390c561f4..4d717826e617f088ede26e91eb1d96bcdc78ed4b 100644 (file)
@@ -639,12 +639,10 @@ public abstract class AbstractField extends AbstractComponent implements Field,
      */
     public boolean isValid() {
 
-        if (isRequired()) {
-            if (isEmpty()) {
+        if (isEmpty()) {
+            if (isRequired()) {
                 return false;
-            }
-        } else {
-            if (isEmpty()) {
+            } else {
                 return true;
             }
         }
@@ -675,9 +673,11 @@ public abstract class AbstractField extends AbstractComponent implements Field,
      */
     public void validate() throws Validator.InvalidValueException {
 
-        if (isRequired()) {
-            if (isEmpty()) {
+        if (isEmpty()) {
+            if (isRequired()) {
                 throw new Validator.EmptyValueException(requiredError);
+            } else {
+                return;
             }
         }