From: Matti Tahvonen Date: Tue, 11 Nov 2008 12:44:10 +0000 (+0000) Subject: added possibility to use dateformat independent from Locale. Fixes #2200 X-Git-Tag: 6.7.0.beta1~3832 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=584d3d9806256210fd5595024d7d7a06796b648a;p=vaadin-framework.git added possibility to use dateformat independent from Locale. Fixes #2200 svn changeset:5862/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java index 46ae202986..7a90f5e1ab 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextualDate.java @@ -56,6 +56,10 @@ public class ITextualDate extends IDateField implements Paintable, Field, // force recreating format string formatStr = null; } + if (uidl.hasAttribute("format")) { + formatStr = uidl.getStringAttribute("format"); + } + buildDate(); // not a FocusWidget -> needs own tabindex handling if (uidl.hasAttribute("tabindex")) { diff --git a/src/com/itmill/toolkit/ui/DateField.java b/src/com/itmill/toolkit/ui/DateField.java index a1859af1b5..7a3d5a00dc 100644 --- a/src/com/itmill/toolkit/ui/DateField.java +++ b/src/com/itmill/toolkit/ui/DateField.java @@ -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; + } + }