]> source.dussan.org Git - vaadin-framework.git/commitdiff
added possibility to use dateformat independent from Locale. Fixes #2200
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 11 Nov 2008 12:44:10 +0000 (12:44 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 11 Nov 2008 12:44:10 +0000 (12:44 +0000)
svn changeset:5862/svn branch:trunk

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

index 46ae202986eac7a3cb349658b0f2cebe4e7f4eea..7a90f5e1ab4d538321eb7daa2e816ee0f3f80ed4 100644 (file)
@@ -56,6 +56,10 @@ public class ITextualDate extends IDateField implements Paintable, Field,
             // force recreating format string\r
             formatStr = null;\r
         }\r
+        if (uidl.hasAttribute("format")) {\r
+            formatStr = uidl.getStringAttribute("format");\r
+        }\r
+\r
         buildDate();\r
         // not a FocusWidget -> needs own tabindex handling\r
         if (uidl.hasAttribute("tabindex")) {\r
index a1859af1b511629cb83aaf652dea19774dcf1c34..7a3d5a00dc7f911ffca19b91edcd6e2cd7da191b 100644 (file)
@@ -102,6 +102,11 @@ public class DateField extends AbstractField {
      */
     private Calendar calendar;
 
+    /**
+     * Overridden format string
+     */
+    private String dateFormat;
+
     /* Constructors */
 
     /**
@@ -183,6 +188,10 @@ public class DateField extends AbstractField {
             target.addAttribute("locale", l.toString());
         }
 
+        if (getDateFormat() != null) {
+            target.addAttribute("format", dateFormat);
+        }
+
         target.addAttribute("type", type);
 
         // Gets the calendar
@@ -433,4 +442,32 @@ public class DateField extends AbstractField {
 
         return newCal;
     }
+
+    /**
+     * Sets formatting used by some component implementations. See
+     * {@link SimpleDateFormat} for format details.
+     * 
+     * By default it is encouraged to used default formatting defined by Locale,
+     * but due some JVM bugs it is sometimes necessary to use this method to
+     * override formatting. See Toolkit issue #2200.
+     * 
+     * @param dateFormat
+     *            the dateFormat to set
+     * 
+     * @see com.itmill.toolkit.ui.AbstractComponent#setLocale(Locale))
+     */
+    public void setDateFormat(String dateFormat) {
+        this.dateFormat = dateFormat;
+    }
+
+    /**
+     * Reterns a format string used to format date value on client side or null
+     * if default formatting from {@link Component#getLocale()} is used.
+     * 
+     * @return the dateFormat
+     */
+    public String getDateFormat() {
+        return dateFormat;
+    }
+
 }