aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2016-09-26 13:46:54 +0300
committerDenis Anisimov <denis@vaadin.com>2016-09-26 13:46:54 +0300
commit0052d59a318075a3ce8202b2eab84e9d643fc544 (patch)
treeae9dce8e660a1759fba44becc4c6deba20b908d4 /server
parent0b5e2f34690a2a0f090a93ea1a63475a22ac3d13 (diff)
downloadvaadin-framework-0052d59a318075a3ce8202b2eab84e9d643fc544.tar.gz
vaadin-framework-0052d59a318075a3ce8202b2eab84e9d643fc544.zip
Update DateRangeValidator to be LocalDate based (#320).
Change-Id: I46500d5dd740b806bfa8c3849c54253c6ae92187
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/data/validator/DateRangeValidator.java26
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractDateField.java10
2 files changed, 13 insertions, 23 deletions
diff --git a/server/src/main/java/com/vaadin/data/validator/DateRangeValidator.java b/server/src/main/java/com/vaadin/data/validator/DateRangeValidator.java
index c07d27eadb..3b8eefa1dd 100644
--- a/server/src/main/java/com/vaadin/data/validator/DateRangeValidator.java
+++ b/server/src/main/java/com/vaadin/data/validator/DateRangeValidator.java
@@ -15,37 +15,25 @@
*/
package com.vaadin.data.validator;
+import java.time.LocalDate;
import java.util.Comparator;
-import java.util.Date;
-
-import com.vaadin.shared.ui.datefield.Resolution;
/**
- * Validator for validating that a Date is inside a given range.
- *
- * <p>
- * Note that the comparison is done directly on the Date object so take care
- * that the hours/minutes/seconds/milliseconds of the min/max values are
- * properly set.
- * </p>
+ * Validator for validating that a {@link LocalDate} is inside a given range.
*
* @author Vaadin Ltd.
* @since 8.0
*/
-public class DateRangeValidator extends RangeValidator<Date> {
+public class DateRangeValidator extends RangeValidator<LocalDate> {
/**
- * Creates a validator for checking that an Date is within a given range.
+ * Creates a validator for checking that a LocalDate is within a given
+ * range.
* <p>
* By default the range is inclusive i.e. both minValue and maxValue are
* valid values. Use {@link #setMinValueIncluded(boolean)} or
* {@link #setMaxValueIncluded(boolean)} to change it.
* </p>
- * <p>
- * Note that the comparison is done directly on the Date object so take care
- * that the hours/minutes/seconds/milliseconds of the min/max values are
- * properly set.
- * </p>
*
* @param errorMessage
* the message to display in case the value does not validate.
@@ -54,8 +42,8 @@ public class DateRangeValidator extends RangeValidator<Date> {
* @param maxValue
* The maximum value to accept or null for no limit
*/
- public DateRangeValidator(String errorMessage, Date minValue, Date maxValue,
- Resolution resolution) {
+ public DateRangeValidator(String errorMessage, LocalDate minValue,
+ LocalDate maxValue) {
super(errorMessage, Comparator.naturalOrder(), minValue, maxValue);
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java
index f8cda4f355..ac945256f7 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java
@@ -17,6 +17,7 @@ package com.vaadin.ui;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.Comparator;
import java.util.Date;
import java.util.EventObject;
import java.util.HashMap;
@@ -28,7 +29,7 @@ import java.util.logging.Logger;
import org.jsoup.nodes.Element;
import com.vaadin.data.Result;
-import com.vaadin.data.validator.DateRangeValidator;
+import com.vaadin.data.validator.RangeValidator;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
@@ -792,9 +793,10 @@ public abstract class AbstractDateField extends AbstractField<Date>
uiHasValidDateString = true;
setComponentError(new UserError(currentParseErrorMessage));
} else {
- DateRangeValidator validator = new DateRangeValidator(
- getDateOutOfRangeMessage(), getRangeStart(getResolution()),
- getRangeEnd(getResolution()), getResolution());
+ RangeValidator<Date> validator = new RangeValidator<>(
+ getDateOutOfRangeMessage(), Comparator.naturalOrder(),
+ getRangeStart(getResolution()),
+ getRangeEnd(getResolution()));
Result<Date> result = validator.apply(value);
if (result.isError()) {
setComponentError(new UserError(getDateOutOfRangeMessage()));