summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/DateField.java
diff options
context:
space:
mode:
authorMiki <miki@vaadin.com>2015-01-16 14:02:19 +0200
committerVaadin Code Review <review@vaadin.com>2015-02-03 11:15:41 +0000
commita508ed7b4aa062334ad84d7967cb2bdd5d8ecc26 (patch)
tree5215ac87b3063efd9d7c8a67d5b3b008ff931b70 /server/src/com/vaadin/ui/DateField.java
parent293b62ab6ed402b188685027b100025597a37d00 (diff)
downloadvaadin-framework-a508ed7b4aa062334ad84d7967cb2bdd5d8ecc26.tar.gz
vaadin-framework-a508ed7b4aa062334ad84d7967cb2bdd5d8ecc26.zip
Declarative for DateFields (and related) with ISO8601 (#16313)
DesignAttributeHandler supports method names that contains some words in uppercase DesignAttributeHandler and other components now use extensible Formatter with Converters rather than static methods Change-Id: I9f68414bd4821f47ff37a26375091d154cae9a93
Diffstat (limited to 'server/src/com/vaadin/ui/DateField.java')
-rw-r--r--server/src/com/vaadin/ui/DateField.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java
index 3d683f4902..422b1ffdd8 100644
--- a/server/src/com/vaadin/ui/DateField.java
+++ b/server/src/com/vaadin/ui/DateField.java
@@ -24,6 +24,9 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
+import java.util.logging.Logger;
+
+import org.jsoup.nodes.Element;
import com.vaadin.data.Property;
import com.vaadin.data.Validator;
@@ -40,6 +43,8 @@ import com.vaadin.server.PaintTarget;
import com.vaadin.shared.ui.datefield.DateFieldConstants;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.shared.ui.datefield.TextualDateFieldState;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
/**
* <p>
@@ -1061,4 +1066,40 @@ public class DateField extends AbstractField<Date> implements
}
}
+
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
+ if (design.hasAttr("value") && !design.attr("value").isEmpty()) {
+ Date date = DesignAttributeHandler.getFormatter().parse(
+ design.attr("value"), Date.class);
+ // formatting will return null if it cannot parse the string
+ if (date == null) {
+ Logger.getLogger(DateField.class.getName()).info(
+ "cannot parse " + design.attr("value") + " as date");
+ }
+ this.setValue(date);
+ }
+ }
+
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+ if (getValue() != null) {
+ design.attr("value",
+ DesignAttributeHandler.getFormatter().format(getValue()));
+ }
+ }
+
+ /**
+ * Returns current date-out-of-range error message.
+ *
+ * @see #setDateOutOfRangeMessage(String)
+ * @since 7.4
+ * @return Current error message for dates out of range.
+ */
+ public String getDateOutOfRangeMessage() {
+ return dateOutOfRangeMessage;
+ }
+
}