diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/DateField.java | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java index e98b1e1b31..ba1178548f 100644 --- a/server/src/com/vaadin/ui/DateField.java +++ b/server/src/com/vaadin/ui/DateField.java @@ -153,6 +153,13 @@ public class DateField extends AbstractField<Date> implements private DateRangeValidator currentRangeValidator; + /** + * Determines whether the ValueChangeEvent should be fired. Used to prevent + * firing the event when UI has invalid string until uiHasValidDateString + * flag is set + */ + private boolean preventValueChangeEvent = false; + static { variableNameForResolution.put(Resolution.SECOND, "sec"); variableNameForResolution.put(Resolution.MINUTE, "min"); @@ -543,13 +550,21 @@ public class DateField extends AbstractField<Date> implements /* * Datefield now contains some text that could't be parsed - * into date. + * into date. ValueChangeEvent is fired after the value is + * changed and the flags are set */ if (oldDate != null) { /* - * Set the logic value to null. + * Set the logic value to null without firing the + * ValueChangeEvent */ - setValue(null); + preventValueChangeEvent = true; + try { + setValue(null); + } finally { + preventValueChangeEvent = false; + } + /* * Reset the dateString (overridden to null by setValue) */ @@ -571,6 +586,13 @@ public class DateField extends AbstractField<Date> implements uiHasValidDateString = false; /* + * If value was changed fire the ValueChangeEvent + */ + if (oldDate != null) { + fireValueChange(false); + } + + /* * Because of our custom implementation of isValid(), that * also checks the parsingSucceeded flag, we must also * notify the form (if this is used in one) that the @@ -603,6 +625,16 @@ public class DateField extends AbstractField<Date> implements } } + /* + * only fires the event if preventValueChangeEvent flag is false + */ + @Override + protected void fireValueChange(boolean repaintIsNotNeeded) { + if (!preventValueChangeEvent) { + super.fireValueChange(repaintIsNotNeeded); + } + } + /** * This method is called to handle a non-empty date string from the client * if the client could not parse it as a Date. |