]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes #2179
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 24 Oct 2008 13:12:32 +0000 (13:12 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 24 Oct 2008 13:12:32 +0000 (13:12 +0000)
svn changeset:5715/svn branch:trunk

src/com/itmill/toolkit/data/Validator.java
src/com/itmill/toolkit/ui/AbstractField.java

index 7f2de6ca13ce1bb0d38a43ee335405ce9a70df6a..3bbd75e3dccf3bfe66ea87e66e7f70dc1a01072e 100644 (file)
@@ -95,9 +95,29 @@ public interface Validator {
                 throw new NullPointerException(
                         "Possible causes array must not be null");
             }
+
             this.causes = causes;
         }
 
+        /**
+         * See if the error message doesn't paint anything visible.
+         * 
+         * @return True iff the paint method does not paint anything visible.
+         */
+        public boolean isInvisible() {
+            if (getMessage() != null) {
+                return false;
+            }
+            if (causes != null) {
+                for (int i = 0; i < causes.length; i++) {
+                    if (!causes[i].isInvisible()) {
+                        return false;
+                    }
+                }
+            }
+            return true;
+        }
+
         public final int getErrorLevel() {
             return ErrorMessage.ERROR;
         }
index fa1faecd0bceb5c9f1fddf0d00910d3a96bbd833..66eef1d6dfbba06b858c708c2b1fa03517daaf83 100644 (file)
@@ -628,6 +628,10 @@ public abstract class AbstractField extends AbstractComponent implements Field,
             if (isEmpty()) {
                 return false;
             }
+        } else {
+            if (isEmpty()) {
+                return true;
+            }
         }
 
         if (validators == null) {
@@ -751,13 +755,14 @@ public abstract class AbstractField extends AbstractComponent implements Field,
         // Check validation errors only if automatic validation is enabled.
         // As an exception, no validation messages are shown for empty
         // required fields, as in those cases user is aware of the problem.
+        // Furthermore, non-required empty fields are obviously correct.
         ErrorMessage validationError = null;
-        if (isValidationVisible()) {
+        if (isValidationVisible() && !isEmpty()) {
+
             try {
                 validate();
             } catch (Validator.InvalidValueException e) {
-                String msg = e.getMessage();
-                if (msg != null && !"".equals(msg)) {
+                if (!e.isInvisible()) {
                     validationError = e;
                 }
             }