diff options
author | Marko Grönroos <magi@iki.fi> | 2008-07-03 13:10:11 +0000 |
---|---|---|
committer | Marko Grönroos <magi@iki.fi> | 2008-07-03 13:10:11 +0000 |
commit | af895f9596858e252685bf73f61ecdbd4d656c6e (patch) | |
tree | c8e9cbac2f7fe5cc4f39bba5549abdb476239ef8 /src/com/itmill/toolkit/ui/Form.java | |
parent | 5e5f0e5990f19f23455d85a84727063e7fcf97f4 (diff) | |
download | vaadin-framework-af895f9596858e252685bf73f61ecdbd4d656c6e.tar.gz vaadin-framework-af895f9596858e252685bf73f61ecdbd4d656c6e.zip |
Fixed #1867 further.
svn changeset:5030/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/Form.java')
-rw-r--r-- | src/com/itmill/toolkit/ui/Form.java | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/com/itmill/toolkit/ui/Form.java b/src/com/itmill/toolkit/ui/Form.java index 5f0863ff51..266aa780d4 100644 --- a/src/com/itmill/toolkit/ui/Form.java +++ b/src/com/itmill/toolkit/ui/Form.java @@ -15,8 +15,10 @@ import com.itmill.toolkit.data.Item; import com.itmill.toolkit.data.Property; import com.itmill.toolkit.data.Validatable; import com.itmill.toolkit.data.Validator; +import com.itmill.toolkit.data.Validator.EmptyValueException; import com.itmill.toolkit.data.Validator.InvalidValueException; import com.itmill.toolkit.data.util.BeanItem; +import com.itmill.toolkit.terminal.CompositeErrorMessage; import com.itmill.toolkit.terminal.ErrorMessage; import com.itmill.toolkit.terminal.PaintException; import com.itmill.toolkit.terminal.PaintTarget; @@ -169,6 +171,17 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, if (formFooter != null) { formFooter.paint(target); } + + // AbstractComponent.paint() does not paint EmptyValueExceptions and + // filters them out, but Form wants to paint them, so we have to + // see if the error was skipped. + // Efficiency note: also AbstractComponent.paint() calls + // getErrorMessage(), which is a bit heavy call. + final ErrorMessage error = getErrorMessage(); + if (error instanceof EmptyValueException || + (error instanceof CompositeErrorMessage && + ((CompositeErrorMessage)error).hasErrorMessageClass(EmptyValueException.class))) + error.paint(target); } /** @@ -182,22 +195,39 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, * validation fails also on empty errors. */ public ErrorMessage getErrorMessage() { + // Reimplement the checking of validation error by using + // getErrorMessage() recursively instead of validate(). + ErrorMessage validationError = null; for (final Iterator i = propertyIds.iterator(); i.hasNext();) { try { AbstractComponent field = (AbstractComponent) fields.get(i .next()); - ErrorMessage e = field.getErrorMessage(); - if (e != null) { + validationError = field.getErrorMessage(); + if (validationError != null) { // Skip empty errors - if ("".equals(e.toString())) { + if (validationError.toString().isEmpty()) continue; - } - return e; + break; } } catch (ClassCastException ignored) { } } - return null; + + // The rest is reimplementation of the latter part of + // AbstractField.getErrorMessage() + + // Check if there are any systems errors + final ErrorMessage superError = super.getErrorMessage(); + + // Return if there are no errors at all + if (superError == null && validationError == null + && currentBufferedSourceException == null) { + return null; + } + + // Throw combination of the error types + return new CompositeErrorMessage(new ErrorMessage[] { superError, + validationError, currentBufferedSourceException }); } /* |