From: Henri Sara Date: Fri, 16 Mar 2012 12:36:47 +0000 (+0200) Subject: Convert hide errors flag to shared state (#8437). X-Git-Tag: 7.0.0.alpha2~256 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6958987e58fcd4354a9ff804d99f27873cefd23b;p=vaadin-framework.git Convert hide errors flag to shared state (#8437). --- diff --git a/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java b/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java index 9376be29f7..bf84e2e606 100644 --- a/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java +++ b/src/com/vaadin/terminal/gwt/client/AbstractFieldState.java @@ -15,6 +15,7 @@ import com.vaadin.ui.AbstractField; */ public class AbstractFieldState extends ComponentState { private boolean propertyReadOnly = false; + private boolean hideErrors = false; /** * Checks if the property data source for the Field is in read only mode. @@ -37,4 +38,28 @@ public class AbstractFieldState extends ComponentState { this.propertyReadOnly = propertyReadOnly; } + /** + * Returns true if the component will hide any errors even if the error + * message is set. + * + * @return true if error messages are disabled + */ + public boolean isHideErrors() { + return hideErrors; + } + + /** + * Sets whether the component should hide any errors even if the error + * message is set. + * + * This is used e.g. on forms to hide error messages for invalid fields + * before the first user actions. + * + * @param hideErrors + * true if error messages should be hidden + */ + public void setHideErrors(boolean hideErrors) { + this.hideErrors = hideErrors; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/VCaption.java b/src/com/vaadin/terminal/gwt/client/VCaption.java index b1adb83db8..56af03b8d1 100644 --- a/src/com/vaadin/terminal/gwt/client/VCaption.java +++ b/src/com/vaadin/terminal/gwt/client/VCaption.java @@ -32,10 +32,7 @@ public class VCaption extends HTML { private int maxWidth = -1; - protected static final String ATTRIBUTE_CAPTION = "caption"; - protected static final String ATTRIBUTE_DESCRIPTION = "description"; protected static final String ATTRIBUTE_REQUIRED = AbstractComponentConnector.ATTRIBUTE_REQUIRED; - protected static final String ATTRIBUTE_HIDEERRORS = AbstractComponentConnector.ATTRIBUTE_HIDEERRORS; private enum InsertPosition { ICON, CAPTION, REQUIRED, ERROR @@ -118,8 +115,11 @@ public class VCaption extends HTML { boolean hasIcon = owner.getState().getIcon() != null; boolean showRequired = uidl .getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_REQUIRED); - boolean showError = owner.getState().getErrorMessage() != null - && !uidl.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_HIDEERRORS); + boolean showError = owner.getState().getErrorMessage() != null; + if (owner.getState() instanceof AbstractFieldState) { + showError = showError + && !((AbstractFieldState) owner.getState()).isHideErrors(); + } if (hasIcon) { if (icon == null) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index e4a444def7..f26aad9d2a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -35,7 +35,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector // Not all references to the string literals have been converted to use // these! public static final String ATTRIBUTE_REQUIRED = "required"; - public static final String ATTRIBUTE_HIDEERRORS = "hideErrors"; private Widget widget; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java index 93b6588898..92d15df618 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java @@ -18,6 +18,7 @@ import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.AbstractFieldState; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -351,8 +352,13 @@ public class VFormLayout extends SimplePanel { public void updateFromUIDL(UIDL uidl, ComponentConnector component) { owner = component; - if (null != owner.getState().getErrorMessage() - && !uidl.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_HIDEERRORS)) { + boolean showError = null != owner.getState().getErrorMessage(); + if (owner.getState() instanceof AbstractFieldState) { + showError = showError + && !((AbstractFieldState) owner.getState()) + .isHideErrors(); + } + if (showError) { if (errorIndicatorElement == null) { errorIndicatorElement = DOM.createDiv(); DOM.setInnerHTML(errorIndicatorElement, " "); diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index a49dbcb913..4da172d395 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -862,6 +862,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource ErrorMessage error = getErrorMessage(); if (null != error) { sharedState.setErrorMessage(error.getFormattedHtmlMessage()); + } else { + sharedState.setErrorMessage(null); } return sharedState; diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 742d39d835..4380506505 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -178,12 +178,6 @@ public abstract class AbstractField extends AbstractComponent implements target.addAttribute(AbstractComponentConnector.ATTRIBUTE_REQUIRED, true); } - - // Hide the error indicator if needed - if (shouldHideErrors()) { - target.addAttribute( - AbstractComponentConnector.ATTRIBUTE_HIDEERRORS, true); - } } /** @@ -1625,7 +1619,12 @@ public abstract class AbstractField extends AbstractComponent implements @Override public AbstractFieldState getState() { - return (AbstractFieldState) super.getState(); + AbstractFieldState state = (AbstractFieldState) super.getState(); + + // Hide the error indicator if needed + state.setHideErrors(shouldHideErrors()); + + return state; } @Override diff --git a/src/com/vaadin/ui/Select.java b/src/com/vaadin/ui/Select.java index e4eb2e68b3..173e96c16d 100644 --- a/src/com/vaadin/ui/Select.java +++ b/src/com/vaadin/ui/Select.java @@ -273,12 +273,6 @@ public class Select extends AbstractSelect implements AbstractSelect.Filtering, currentPage = -1; // current page is always set by client optionRequest = true; - - // Hide the error indicator if needed - if (shouldHideErrors()) { - target.addAttribute( - AbstractComponentConnector.ATTRIBUTE_HIDEERRORS, true); - } } /**