From: elmot Date: Tue, 1 Aug 2017 10:42:37 +0000 (+0300) Subject: Null handling, review fixes X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Freviewable%2Fpr9740%2Fr3;p=vaadin-framework.git Null handling, review fixes --- diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index e35840b62f..12e94a691c 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -229,22 +229,28 @@ public abstract class AbstractDateField parsedDate = handleUnparsableDateString(dateString); - parsedDate.ifOk(this::setValue); + parsedDate.ifOk(v-> { + uiHasValidDateString = true; + currentParseErrorMessage = null; + setValue(v,true); + }); if (parsedDate.isError()) { - doSetValue(null); dateString = null; uiHasValidDateString = false; currentParseErrorMessage = parsedDate.getMessage().orElse("Parsing error"); setComponentError(new UserError(getParseErrorMessage())); + setValue(null,true); } } else { + uiHasValidDateString = true; + currentParseErrorMessage = null; setValue(newDate, true); } } @@ -443,34 +449,6 @@ public abstract class AbstractDateField binder = new Binder<>(); - binder.forField(dateField).withStatusLabel(errorLabel).bind(o -> dateField.getEmptyValue(), null); + binder.forField(dateField).withStatusLabel(errorLabel).bind(o -> dateField.getValue(), null); Button button = new Button("Validate!"); button.addClickListener(event1 -> { diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldIsValidTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldIsValidTest.java index b7df7d7f20..dacbae3db1 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldIsValidTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldIsValidTest.java @@ -46,14 +46,15 @@ public class DateFieldIsValidTest extends MultiBrowserTest { assertLogText("2. buttonClick: value: 01/01/01, is valid: true"); dateTextbox.sendKeys("lala", Keys.TAB); + assertLogText("3. valueChange: value: null, is valid: false"); button.click(); - assertLogText("3. buttonClick: value: null, is valid: false"); + assertLogText("4. buttonClick: value: null, is valid: false"); dateTextbox.clear(); dateTextbox.sendKeys("02/02/02", Keys.TAB); - assertLogText("4. valueChange: value: 02/02/02, is valid: true"); + assertLogText("5. valueChange: value: 02/02/02, is valid: true"); button.click(); - assertLogText("5. buttonClick: value: 02/02/02, is valid: true"); + assertLogText("6. buttonClick: value: 02/02/02, is valid: true"); } private void assertLogText(String expected) throws Exception { diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTextHandlingTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTextHandlingTest.java index e347bdbf3b..6a264b1575 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTextHandlingTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateTextHandlingTest.java @@ -13,18 +13,20 @@ import org.openqa.selenium.WebElement; import static org.junit.Assert.assertEquals; public class DateTextHandlingTest extends SingleBrowserTest { + + public static final String Y2K_GB_LOCALE = "01-Jan-2000"; + @Test public void testSpecialValue() throws InterruptedException { openTestURL(); DateFieldElement dateFieldElement = $(DateFieldElement.class).first(); ButtonElement validate = $(ButtonElement.class).first(); - LabelElement validateResult = $(LabelElement.class).first(); WebElement dateTextbox = dateFieldElement .findElement(com.vaadin.testbench.By.className("v-textfield")); dateTextbox.sendKeys("Y2K",Keys.TAB); validate.click(); - assertNotification("Y2K Sould be converted to 1-JAN-2000", "01-Jan-2000"); + assertNotification("Y2K Should be converted to " + Y2K_GB_LOCALE, Y2K_GB_LOCALE); dateTextbox.clear(); validate.click(); diff --git a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java index 60b66f05bf..5e6ab39c6b 100644 --- a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java +++ b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java @@ -64,7 +64,7 @@ public class AbstractTextElementSetValueTest extends MultiBrowserTest { LabelElement eventCount = $(LabelElement.class).get(4); // we can type any string in date field element elem.setValue(TYPED_STRING); - // invalid values are cleared stays + // invalid values should stay unchanged Assert.assertEquals(TYPED_STRING, elem.getValue()); }