summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Wagner <wbadam@users.noreply.github.com>2018-02-02 12:25:35 +0200
committerIlia Motornyi <elmot@vaadin.com>2018-02-02 12:25:35 +0200
commitd2ef29e5b41d45f291d087760b02e212c75ff9eb (patch)
treef13c6e19627f96c11a8edce9d49e72e6867f3ed6
parent875c98972e9c3da25a7c9c54cb267871921d4804 (diff)
downloadvaadin-framework-d2ef29e5b41d45f291d087760b02e212c75ff9eb.tar.gz
vaadin-framework-d2ef29e5b41d45f291d087760b02e212c75ff9eb.zip
Add flush() implementation to DateField (#10518)
Fixes #10488
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java27
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VDateField.java13
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java20
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VDateTimeFieldCalendar.java9
-rw-r--r--client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java7
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldShortcut.java44
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldShortcutTest.java39
7 files changed, 143 insertions, 16 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java b/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java
index daa2701e2a..409dc0ef7f 100644
--- a/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java
+++ b/client/src/main/java/com/vaadin/client/ui/VAbstractTextualDate.java
@@ -227,8 +227,19 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
}
@Override
- @SuppressWarnings("deprecation")
public void onChange(ChangeEvent event) {
+ updateBufferedValues();
+ sendBufferedValues();
+ }
+
+ @Override
+ public void updateBufferedValues() {
+ updateDate();
+ bufferedDateString = text.getText();
+ updateBufferedResolutions();
+ }
+
+ private void updateDate() {
if (!text.getText().isEmpty()) {
try {
String enteredDate = text.getText();
@@ -259,10 +270,6 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
// remove possibly added invalid value indication
removeStyleName(getStylePrimaryName() + PARSE_ERROR_CLASSNAME);
}
-
- // always send the date string
- bufferedDateString = text.getText();
- updateAndSendBufferedValues();
}
/**
@@ -270,7 +277,10 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
* then {@link #sendBufferedValues() sends} the values to the server.
*
* @since 8.2
+ * @deprecated Use {@link #updateBufferedResolutions()} and
+ * {@link #sendBufferedValues()} instead.
*/
+ @Deprecated
protected final void updateAndSendBufferedValues() {
updateBufferedResolutions();
sendBufferedValues();
@@ -285,8 +295,8 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
* method.
*
* <p>
- * Note that this method should not send the buffered values, but use
- * {@link #updateAndSendBufferedValues()} instead
+ * Note that this method should not send the buffered values. For that, use
+ * {@link #sendBufferedValues()}.
*
* @since 8.2
*/
@@ -482,7 +492,8 @@ public abstract class VAbstractTextualDate<R extends Enum<R>>
date = getIsoFormatter().parse(isoDate);
}
setDate(date);
- updateAndSendBufferedValues();
+ updateBufferedResolutions();
+ sendBufferedValues();
}
/**
diff --git a/client/src/main/java/com/vaadin/client/ui/VDateField.java b/client/src/main/java/com/vaadin/client/ui/VDateField.java
index 39aeda26c4..21ad59b4ba 100644
--- a/client/src/main/java/com/vaadin/client/ui/VDateField.java
+++ b/client/src/main/java/com/vaadin/client/ui/VDateField.java
@@ -263,6 +263,19 @@ public abstract class VDateField<R extends Enum<R>> extends FlowPanel
}
/**
+ * Update buffered values {@link #bufferedDateString} and
+ * {@link #bufferedResolutions} that will be sent to the server.
+ * <p>
+ * This method should NOT send values to the server.
+ * <p>
+ * This method can be implemented by subclasses to update buffered values
+ * from component values.
+ *
+ * @since
+ */
+ public abstract void updateBufferedValues();
+
+ /**
* Sends the {@link #bufferedDateString} and {@link #bufferedResolutions} to
* the server, and clears their values.
*
diff --git a/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java b/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java
index 6e727ee640..42e8f9dc97 100644
--- a/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java
+++ b/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java
@@ -38,14 +38,8 @@ public class VDateFieldCalendar
super(GWT.create(VDateCalendarPanel.class), YEAR);
}
- /**
- * TODO refactor: almost same method as in VPopupCalendar.updateValue
- * <p>
- * For internal use only. May be removed or replaced in the future.
- */
@Override
- @SuppressWarnings("deprecation")
- public void updateValueFromPanel() {
+ public void updateBufferedValues() {
// If field is invisible at the beginning, client can still be null when
// this function is called.
if (getClient() == null) {
@@ -67,6 +61,18 @@ public class VDateFieldCalendar
bufferedResolutions.put(DAY, date2.getDate());
}
}
+ }
+ }
+
+ /**
+ * TODO refactor: almost same method as in VPopupCalendar.updateValue
+ * <p>
+ * For internal use only. May be removed or replaced in the future.
+ */
+ @Override
+ public void updateValueFromPanel() {
+ updateBufferedValues();
+ if (bufferedResolutions != null) {
sendBufferedValues();
}
}
diff --git a/client/src/main/java/com/vaadin/client/ui/VDateTimeFieldCalendar.java b/client/src/main/java/com/vaadin/client/ui/VDateTimeFieldCalendar.java
index a635b8b615..a6c6cc75be 100644
--- a/client/src/main/java/com/vaadin/client/ui/VDateTimeFieldCalendar.java
+++ b/client/src/main/java/com/vaadin/client/ui/VDateTimeFieldCalendar.java
@@ -43,7 +43,7 @@ public class VDateTimeFieldCalendar extends
}
@Override
- public void updateValueFromPanel() {
+ public void updateBufferedValues() {
// If field is invisible at the beginning, client can still be null when
// this function is called.
if (getClient() == null) {
@@ -72,6 +72,13 @@ public class VDateTimeFieldCalendar extends
}
}
}
+ }
+ }
+
+ @Override
+ public void updateValueFromPanel() {
+ updateBufferedValues();
+ if (bufferedResolutions != null) {
sendBufferedValues();
}
}
diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java
index 35d1c1c4d1..b3ed6cd118 100644
--- a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java
@@ -167,6 +167,13 @@ public abstract class AbstractDateFieldConnector<R extends Enum<R>>
calendar.updateAssistiveLabels();
}
+ @Override
+ public void flush() {
+ super.flush();
+ getWidget().updateBufferedValues();
+ getWidget().sendBufferedValues();
+ }
+
private static Logger getLogger() {
return Logger.getLogger(AbstractDateFieldConnector.class.getName());
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldShortcut.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldShortcut.java
new file mode 100644
index 0000000000..406e13a5a3
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldShortcut.java
@@ -0,0 +1,44 @@
+package com.vaadin.tests.components.datefield;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.event.ShortcutAction.KeyCode;
+import com.vaadin.event.ShortcutListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.Notification;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class DateFieldShortcut extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ String dateFormat = "dd/MM/yyyy";
+
+ DateField dateField = new DateField();
+ dateField.setValue(LocalDate.of(2018, 1, 11));
+ dateField.setDateFormat(dateFormat);
+
+ dateField.addShortcutListener(
+ new ShortcutListener("Enter", KeyCode.ENTER, null) {
+ @Override
+ public void handleAction(Object sender, Object target) {
+ Notification.show(dateField.getValue()
+ .format(DateTimeFormatter
+ .ofPattern(dateFormat)));
+ }
+ });
+
+ addComponent(dateField);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Modify the date maually (without using the popup element) and"
+ + " then press Enter. The notification should show the modified"
+ + " value instead of the old value.";
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldShortcutTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldShortcutTest.java
new file mode 100644
index 0000000000..3e01a41b43
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldShortcutTest.java
@@ -0,0 +1,39 @@
+package com.vaadin.tests.components.datefield;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.DateFieldElement;
+import com.vaadin.testbench.elements.NotificationElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+import static org.junit.Assert.assertEquals;
+
+public class DateFieldShortcutTest extends SingleBrowserTest {
+
+ private static final String DATEFIELD_VALUE_ORIGINAL = "11/01/2018";
+ private static final String DATEFIELD_VALUE_MODIFIED = "21/01/2018";
+
+ @Test
+ public void modifyValueAndPressEnter() {
+ openTestURL();
+
+ DateFieldElement dateField = $(DateFieldElement.class).first();
+ WebElement dateFieldText = dateField.findElement(By.tagName("input"));
+
+ assertEquals("DateField value should be \"" + DATEFIELD_VALUE_ORIGINAL
+ + "\"", DATEFIELD_VALUE_ORIGINAL, dateField.getValue());
+
+ dateFieldText.click();
+ dateFieldText.sendKeys(Keys.HOME, Keys.DELETE, "2");
+ dateFieldText.sendKeys(Keys.ENTER);
+
+ assertEquals("DateField value should be \"" + DATEFIELD_VALUE_MODIFIED
+ + "\"", DATEFIELD_VALUE_MODIFIED, dateField.getValue());
+
+ assertEquals(DATEFIELD_VALUE_MODIFIED,
+ $(NotificationElement.class).first().getCaption());
+ }
+}