From 66e68f1ef25804dabfb4b0e4cdd7d59c66522927 Mon Sep 17 00:00:00 2001 From: Olli Tietäväinen Date: Thu, 10 Aug 2017 15:57:27 +0300 Subject: Enable setting non-selected default value for DateField (#9745) Requested feature: allow setting DateField to a certain starting point without selecting a value. --- .../main/java/com/vaadin/ui/AbstractDateField.java | 115 +++++++++++++++++---- 1 file changed, 94 insertions(+), 21 deletions(-) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index 9d063af5ec..2ad976a7fe 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -79,6 +79,12 @@ public abstract class AbstractDateField parsedDate = handleUnparsableDateString(dateString); - parsedDate.ifOk(v-> { + Result parsedDate = handleUnparsableDateString( + dateString); + parsedDate.ifOk(v -> { uiHasValidDateString = true; currentParseErrorMessage = null; - setValue(v,true); + setValue(v, true); }); if (parsedDate.isError()) { dateString = null; uiHasValidDateString = false; - currentParseErrorMessage = parsedDate.getMessage().orElse("Parsing error"); - setComponentError(new UserError(getParseErrorMessage())); - setValue(null,true); + currentParseErrorMessage = parsedDate.getMessage() + .orElse("Parsing error"); + setComponentError( + new UserError(getParseErrorMessage())); + setValue(null, true); } } else { uiHasValidDateString = true; @@ -272,16 +289,16 @@ public abstract class AbstractDateField variables, T oldDate) { + protected T reconstructDateFromFields(Map variables, + T oldDate) { Map calendarFields = new HashMap<>(); - for (R resolution : getResolutionsHigherOrEqualTo( - getResolution())) { + for (R resolution : getResolutionsHigherOrEqualTo(getResolution())) { // Only handle what the client is allowed to send. The same // resolutions that are painted String variableName = getResolutionVariable(resolution); @@ -290,7 +307,8 @@ public abstract class AbstractDateField= 0) { calendarFields.put(resolution, newValue); } else { - calendarFields.put(resolution, getDatePart(oldDate, resolution)); + calendarFields.put(resolution, + getDatePart(oldDate, resolution)); } } return buildDate(calendarFields); @@ -459,6 +477,57 @@ public abstract class AbstractDateField validator = getRangeValidator();// TODO move range check to internal validator? + RangeValidator validator = getRangeValidator();// TODO move range + // check to internal + // validator? ValidationResult result = validator.apply(value, new ValueContext(this, this)); if (result.isError()) { -- cgit v1.2.3