summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Pòˆntelin <teemu@vaadin.com>2014-05-22 21:22:09 +0300
committerVaadin Code Review <review@vaadin.com>2014-06-18 06:23:43 +0000
commit26f74f5b45dc5d7c2646b792d1ac12851eed1285 (patch)
tree60d30db54dd6fc9bd3c91496c3342cceeb289c73
parent3200aecd5d7c55aadc3142025221b4cc87bd2e22 (diff)
downloadvaadin-framework-26f74f5b45dc5d7c2646b792d1ac12851eed1285.tar.gz
vaadin-framework-26f74f5b45dc5d7c2646b792d1ac12851eed1285.zip
Fixed an NPE while changing a DateField from 24 to 12h clock (#13722)
A client-side NullPointerException was fixed by not reusing the existing VTime panel and always recreating it instead. Otherwise the ListBox for switching between AM/PM might have been null. Change-Id: I8d54d91627043a12b52ac5d5e54d6f7a729af1ac
-rw-r--r--client/src/com/vaadin/client/ui/VCalendarPanel.java4
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/LocaleChange.java82
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/LocaleChangeTest.java62
3 files changed, 145 insertions, 3 deletions
diff --git a/client/src/com/vaadin/client/ui/VCalendarPanel.java b/client/src/com/vaadin/client/ui/VCalendarPanel.java
index d8c96917d8..eaa2292c69 100644
--- a/client/src/com/vaadin/client/ui/VCalendarPanel.java
+++ b/client/src/com/vaadin/client/ui/VCalendarPanel.java
@@ -813,14 +813,12 @@ public class VCalendarPanel extends FocusableFlexTable implements
buildCalendarBody();
}
- if (isTimeSelectorNeeded() && time == null) {
+ if (isTimeSelectorNeeded()) {
time = new VTime();
setWidget(2, 0, time);
getFlexCellFormatter().setColSpan(2, 0, 5);
getFlexCellFormatter().setStyleName(2, 0,
parent.getStylePrimaryName() + "-calendarpanel-time");
- } else if (isTimeSelectorNeeded()) {
- time.updateTimes();
} else if (time != null) {
remove(time);
}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/LocaleChange.java b/uitest/src/com/vaadin/tests/components/datefield/LocaleChange.java
new file mode 100644
index 0000000000..f69c93419b
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/LocaleChange.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.datefield;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.datefield.Resolution;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.DateField;
+
+public class LocaleChange extends AbstractTestUI {
+
+ private final Locale locale12hClock = Locale.US;
+ private final Locale locale24hClock = Locale.FRANCE;
+
+ private final String caption = "Switch to %s hour clock";
+ private static final Date dateValue;
+ static {
+ try {
+ dateValue = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
+ .parse("2014-05-22 20:00:00");
+ } catch (ParseException e) {
+ throw new ExceptionInInitializerError("Should never happen.");
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final DateField df = new DateField();
+ df.setLocale(locale24hClock);
+ df.setResolution(Resolution.SECOND);
+ df.setValue(dateValue);
+
+ Button button = new Button(String.format(caption, "12"));
+ button.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ if (locale12hClock.equals(df.getLocale())) {
+ df.setLocale(locale24hClock);
+ event.getButton().setCaption(String.format(caption, "12"));
+ } else {
+ df.setLocale(locale12hClock);
+ event.getButton().setCaption(String.format(caption, "24"));
+ }
+ }
+ });
+
+ addComponent(df);
+ addComponent(button);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Testing locale change from one with 24h clock to a 12h clock locale.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 13722;
+ }
+} \ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/components/datefield/LocaleChangeTest.java b/uitest/src/com/vaadin/tests/components/datefield/LocaleChangeTest.java
new file mode 100644
index 0000000000..cf756034a1
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/LocaleChangeTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.datefield;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class LocaleChangeTest extends MultiBrowserTest {
+
+ @Test
+ public void testLocaleChange() {
+ openTestURL();
+
+ // Check the initial value and that popup can be opened.
+ assertEquals("22/05/14 20:00:00", getDateValue());
+ toggleDatePopup();
+ assertPopupOpen(true);
+
+ // Close the popup and change the locale.
+ toggleDatePopup();
+ assertPopupOpen(false);
+ driver.findElement(By.className("v-button")).click(); // Locale change.
+
+ // Check that the value has changed and the popup can still be opened
+ // without problems.
+ assertEquals("5/22/14 08:00:00 PM", getDateValue());
+ toggleDatePopup();
+ assertPopupOpen(true);
+ }
+
+ private void assertPopupOpen(boolean open) {
+ assertEquals("Date popup was not " + (open ? "open" : "closed") + ".",
+ (open ? 1 : 0),
+ driver.findElements(By.className("v-datefield-popup")).size());
+ }
+
+ private void toggleDatePopup() {
+ driver.findElement(By.className("v-datefield-button")).click();
+ }
+
+ private String getDateValue() {
+ return driver.findElement(By.className("v-datefield-textfield"))
+ .getAttribute("value");
+ }
+}