]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed an NPE while changing a DateField from 24 to 12h clock (#13722)
authorTeemu Pòˆntelin <teemu@vaadin.com>
Thu, 22 May 2014 18:22:09 +0000 (21:22 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 18 Jun 2014 06:23:43 +0000 (06:23 +0000)
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

client/src/com/vaadin/client/ui/VCalendarPanel.java
uitest/src/com/vaadin/tests/components/datefield/LocaleChange.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/datefield/LocaleChangeTest.java [new file with mode: 0644]

index d8c96917d8d8746961322cc2f3f8a9509a2c43f2..eaa2292c69bafad3bd9e1a2ea4e52e4e469eba4a 100644 (file)
@@ -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 (file)
index 0000000..f69c934
--- /dev/null
@@ -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 (file)
index 0000000..cf75603
--- /dev/null
@@ -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");
+    }
+}