summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Pöntelin <teemu@vaadin.com>2014-12-08 23:21:08 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-09 08:59:06 +0000
commit206055708b0a8e1c17a8c63d482a5e202d3ebf6d (patch)
treefaf2a993be3b18a8d10b28e64718c3e91a250810
parent7e8b23a73a5dd1bef54b8fc5ddc4d3c431c298af (diff)
downloadvaadin-framework-206055708b0a8e1c17a8c63d482a5e202d3ebf6d.tar.gz
vaadin-framework-206055708b0a8e1c17a8c63d482a5e202d3ebf6d.zip
Fix issues when using java.sql.Date as DateField range (#15342)
Change-Id: I656cc0600f929239605e17ab9cf71dc1ba96582f
-rw-r--r--server/src/com/vaadin/ui/DateField.java14
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDate.java54
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDateTest.java51
3 files changed, 113 insertions, 6 deletions
diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java
index 030bd5f6c2..d5700c4b65 100644
--- a/server/src/com/vaadin/ui/DateField.java
+++ b/server/src/com/vaadin/ui/DateField.java
@@ -316,10 +316,10 @@ public class DateField extends AbstractField<Date> implements
throw new IllegalStateException(
"startDate cannot be later than endDate");
}
- getState().rangeStart = startDate;
- // rangeStart = startDate;
- // This has to be done to correct for the resolution
- // updateRangeState();
+
+ // Create a defensive copy against issues when using java.sql.Date (and
+ // also against mutable Date).
+ getState().rangeStart = new Date(startDate.getTime());
updateRangeValidator();
}
@@ -436,8 +436,10 @@ public class DateField extends AbstractField<Date> implements
throw new IllegalStateException(
"endDate cannot be earlier than startDate");
}
- // rangeEnd = endDate;
- getState().rangeEnd = endDate;
+
+ // Create a defensive copy against issues when using java.sql.Date (and
+ // also against mutable Date).
+ getState().rangeEnd = new Date(endDate.getTime());
updateRangeValidator();
}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDate.java b/uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDate.java
new file mode 100644
index 0000000000..74d3e85892
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDate.java
@@ -0,0 +1,54 @@
+/*
+ * 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 com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+
+public class DateRangeWithSqlDate extends AbstractTestUI {
+
+ // 2014-12-01
+ private static final java.sql.Date startDate = new java.sql.Date(
+ 1417467822699L);
+
+ // 2014-12-02
+ private static final java.sql.Date endDate = new java.sql.Date(
+ 1417554763317L);
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ DateField df = new InlineDateField();
+ df.setRangeStart(startDate);
+ df.setRangeEnd(endDate);
+
+ df.setValue(startDate);
+
+ addComponent(df);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test that java.sql.Date can be given to specify date range start and end dates.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 15342;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDateTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDateTest.java
new file mode 100644
index 0000000000..2352011585
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/DateRangeWithSqlDateTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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 java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class DateRangeWithSqlDateTest extends MultiBrowserTest {
+
+ @Test
+ public void testDateRange() {
+ openTestURL();
+
+ // Get all cells of the inline datefield.
+ List<WebElement> cells = driver.findElements(By
+ .className("v-inline-datefield-calendarpanel-day"));
+
+ // Verify the range is rendered correctly.
+ assertCell(cells.get(0), "30", true);
+ assertCell(cells.get(1), "1", false);
+ assertCell(cells.get(2), "2", false);
+ assertCell(cells.get(3), "3", true);
+ }
+
+ private void assertCell(WebElement cell, String text, boolean outsideRange) {
+ assertEquals(text, cell.getText());
+ assertEquals(outsideRange,
+ cell.getAttribute("class").contains("outside-range"));
+ }
+
+}