]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged #2829 to 6.0: Could not distinguish an empty DateField from a DateField contai...
authorHenri Sara <henri.sara@itmill.com>
Wed, 8 Apr 2009 12:21:43 +0000 (12:21 +0000)
committerHenri Sara <henri.sara@itmill.com>
Wed, 8 Apr 2009 12:21:43 +0000 (12:21 +0000)
svn changeset:7365/svn branch:6.0

src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java
src/com/itmill/toolkit/ui/DateField.java

index e68342dcf654518cab6047c161a3f59c2ddb7a85..dcd411c12953057c749265227dd303d932b670e7 100644 (file)
@@ -155,6 +155,7 @@ public class ITextualDate extends IDateField implements Paintable, Field,
                     ClientExceptionHandler.displayError(e.getMessage());\r
 \r
                     addStyleName(PARSE_ERROR_CLASSNAME);\r
+                    // this is a hack that may eventually be removed\r
                     client.updateVariable(id, "lastInvalidDateString", text\r
                             .getText(), false);\r
                     date = null;\r
@@ -164,6 +165,8 @@ public class ITextualDate extends IDateField implements Paintable, Field,
                 // remove possibly added invalid value indication\r
                 removeStyleName(PARSE_ERROR_CLASSNAME);\r
             }\r
+            // always send the date string\r
+            client.updateVariable(id, "dateString", text.getText(), false);\r
 \r
             if (date != null) {\r
                 showingDate = new Date(date.getTime());\r
index aaa53e3ee102fdbcc5400783c187554b31ea8d58..96ddc08b9e1698d0174e29a9fa57de2861f294c0 100644 (file)
@@ -107,6 +107,12 @@ public class DateField extends AbstractField {
      */
     private String dateFormat;
 
+    /**
+     * Read-only content of an ITextualDate field - null for other types of date
+     * fields.
+     */
+    private String dateString;
+
     /* Constructors */
 
     /**
@@ -258,13 +264,23 @@ public class DateField extends AbstractField {
                         || variables.containsKey("day")
                         || variables.containsKey("hour")
                         || variables.containsKey("min")
-                        || variables.containsKey("sec") || variables
-                        .containsKey("msec"))) {
+                        || variables.containsKey("sec")
+                        || variables.containsKey("msec") || variables
+                        .containsKey("dateString"))) {
 
             // Old and new dates
             final Date oldDate = (Date) getValue();
+            final String oldDateString = dateString;
             Date newDate = null;
 
+            // this enables analyzing invalid input on the server
+            Object o = variables.get("dateString");
+            if (o != null) {
+                dateString = o.toString();
+            } else {
+                dateString = null;
+            }
+
             // Gets the new date in parts
             // Null values are converted to negative values.
             int year = variables.containsKey("year") ? (variables.get("year") == null ? -1
@@ -326,10 +342,39 @@ public class DateField extends AbstractField {
                     && (newDate == null || !newDate.equals(oldDate))) {
                 setValue(newDate, true); // Don't require a repaint, client
                 // updates itself
+            } else if (dateString != null && !"".equals(dateString)
+                    && !dateString.equals(oldDateString)) {
+                setValue(handleUnparsableDateString(dateString));
             }
         }
     }
 
+    /**
+     * This method is called to handle the date string from the client if the
+     * client could not parse it as a Date.
+     * 
+     * By default, null is returned. If an exception is thrown, the current
+     * value will not be modified.
+     * 
+     * This can be overridden to handle conversions or to throw an exception, or
+     * to fire an event.
+     * 
+     * The default behavior is likely to change in the next major version of the
+     * toolkit - a Property.ConversionException will be thrown.
+     * 
+     * @param dateString
+     * @return parsed Date
+     * @throws Property.ConversionException
+     *             to keep the old value and indicate an error
+     */
+    protected Date handleUnparsableDateString(String dateString)
+            throws Property.ConversionException {
+        // TODO in the next major version, this should throw an exception to be
+        // consistent with other fields
+        // throw new Property.ConversionException();
+        return null;
+    }
+
     /* Property features */
 
     /*