diff options
author | Henri Sara <hesara@vaadin.com> | 2012-03-16 16:29:01 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-03-21 17:52:39 +0200 |
commit | 5f1c86d93e5b295c0909d792ef20a53c405aa0a1 (patch) | |
tree | 15126162e662cec9bf1cdeee9250009e7faa6cc0 /src/com/vaadin/ui/AbstractField.java | |
parent | 6958987e58fcd4354a9ff804d99f27873cefd23b (diff) | |
download | vaadin-framework-5f1c86d93e5b295c0909d792ef20a53c405aa0a1.tar.gz vaadin-framework-5f1c86d93e5b295c0909d792ef20a53c405aa0a1.zip |
Transfer required attribute in shared state (#8436).
The flag should be used directly from shared state, but that requires
error message etc. related updates to be done in a listener before
sending states.
Diffstat (limited to 'src/com/vaadin/ui/AbstractField.java')
-rw-r--r-- | src/com/vaadin/ui/AbstractField.java | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 4380506505..3fbcfd6b64 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -32,7 +32,6 @@ import com.vaadin.terminal.ErrorMessage; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.AbstractFieldState; -import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; /** * <p> @@ -134,6 +133,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements /** * Required field. */ + // TODO should be used directly from shared state, but requires a listener + // for updating state before it is sent private boolean required = false; /** @@ -172,12 +173,6 @@ public abstract class AbstractField<T> extends AbstractComponent implements if (isModified()) { target.addAttribute("modified", true); } - - // Adds the required attribute - if (!isReadOnly() && isRequired()) { - target.addAttribute(AbstractComponentConnector.ATTRIBUTE_REQUIRED, - true); - } } /** @@ -192,8 +187,9 @@ public abstract class AbstractField<T> extends AbstractComponent implements * to show it when there are errors */ protected boolean shouldHideErrors() { - return isRequired() && isEmpty() && getComponentError() == null - && getErrorMessage() != null; + // getErrorMessage() can still return something else than null based on + // validation etc. + return isRequired() && isEmpty() && getComponentError() == null; } /** @@ -1406,7 +1402,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements * field isEmpty() regardless of any attached validators. * * - * @return <code>true</code> if the field is required .otherwise + * @return <code>true</code> if the field is required, otherwise * <code>false</code>. */ public boolean isRequired() { @@ -1621,7 +1617,12 @@ public abstract class AbstractField<T> extends AbstractComponent implements public AbstractFieldState getState() { AbstractFieldState state = (AbstractFieldState) super.getState(); + // TODO should be directly in state when listener for updates before + // sending state is implemented + state.setRequired(isRequired()); + // Hide the error indicator if needed + // TODO these should be in a listener called before sending state state.setHideErrors(shouldHideErrors()); return state; |