From ae565a229325f1289348c2c0e3dc02f14ed6f549 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Patrik=20Lindstr=C3=B6m?= Date: Wed, 3 Jul 2013 00:04:35 +0300 Subject: [PATCH] Fix bug in PopupDateField where locale was retained incorrectly if changed while popup was open (#12153) Change-Id: Ib4bebab8c6e75e7f1af7cfc5198ab6516e94a45e --- .../ui/datefield/PopupDateFieldConnector.java | 9 ++++ .../datefield/PopupDateFieldLocaleTest.html | 42 +++++++++++++++ .../datefield/PopupDateFieldLocaleTest.java | 53 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.html create mode 100644 uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.java diff --git a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java index b3bb481658..7257af4a08 100644 --- a/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java +++ b/client/src/com/vaadin/client/ui/datefield/PopupDateFieldConnector.java @@ -42,6 +42,9 @@ public class PopupDateFieldConnector extends TextualDateConnector { @Override @SuppressWarnings("deprecation") public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + + String oldLocale = getWidget().getCurrentLocale(); + boolean lastReadOnlyState = getWidget().isReadonly(); boolean lastEnabledState = getWidget().isEnabled(); @@ -64,6 +67,12 @@ public class PopupDateFieldConnector extends TextualDateConnector { getWidget().calendar.renderCalendar(); } } + + // Force re-render of calendar if locale has changed (#12153) + if (getWidget().getCurrentLocale() != oldLocale) { + getWidget().calendar.renderCalendar(); + } + getWidget().calendarToggle.setEnabled(getWidget().isEnabled()); if (getWidget().getCurrentResolution().getCalendarField() <= Resolution.MONTH diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.html b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.html new file mode 100644 index 0000000000..932ad0646e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.html @@ -0,0 +1,42 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.datefield.PopupDateFieldLocaleTest?restartApplication
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldLocaleTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VPopupCalendar[0]/domChild[1]15,18
mouseClick//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[2]/td/table/tbody/tr[4]/td[4]/span19,11
mouseClickvaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldLocaleTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VPopupCalendar[0]/domChild[1]4,14
assertTextPresentjanvier 2000
+ + diff --git a/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.java b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.java new file mode 100644 index 0000000000..f12a3dda58 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.components.datefield; + +import java.util.Calendar; +import java.util.Locale; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.DateField; +import com.vaadin.ui.PopupDateField; + +public class PopupDateFieldLocaleTest extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + // Set a specific time for the PopupDateField + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.YEAR, 2000); + cal.set(Calendar.DAY_OF_YEAR, 1); + cal.set(Calendar.HOUR_OF_DAY, 1); + cal.set(Calendar.MINUTE, 1); + cal.set(Calendar.SECOND, 1); + cal.set(Calendar.MILLISECOND, 1); + + final PopupDateField pdf = new PopupDateField(); + pdf.setLocale(Locale.ENGLISH); + pdf.setValue(cal.getTime()); + pdf.setImmediate(true); + pdf.setResolution(DateField.RESOLUTION_SEC); + addComponent(pdf); + + pdf.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + pdf.setLocale(Locale.FRENCH); + } + }); + } + + @Override + protected String getTestDescription() { + return "Changing the locale while the popupdatefield is visible can " + + "result in the locale remaining at the previous value; the locale " + + "is only changed once the current month is changed."; + } + + @Override + protected Integer getTicketNumber() { + return 12135; + } + +} \ No newline at end of file -- 2.39.5