aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2017-03-27 16:04:35 +0300
committerHenri Sara <henri.sara@gmail.com>2017-03-30 11:20:55 +0300
commit1f09abde4cfa5a6c12508749b51b4ddd7f31f6db (patch)
tree140d5a86f858eef81912b94e7c9273f58e0ce93a
parentad7a7e83c7c472560947ed2259e216808e8a07cf (diff)
downloadvaadin-framework-1f09abde4cfa5a6c12508749b51b4ddd7f31f6db.tar.gz
vaadin-framework-1f09abde4cfa5a6c12508749b51b4ddd7f31f6db.zip
Fix Binder documentation on ValidationException (#8949)
-rw-r--r--documentation/datamodel/datamodel-forms.asciidoc2
-rw-r--r--server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java30
2 files changed, 31 insertions, 1 deletions
diff --git a/documentation/datamodel/datamodel-forms.asciidoc b/documentation/datamodel/datamodel-forms.asciidoc
index 3db83d6436..a565e2ed01 100644
--- a/documentation/datamodel/datamodel-forms.asciidoc
+++ b/documentation/datamodel/datamodel-forms.asciidoc
@@ -54,7 +54,7 @@ Button saveButton = new Button("Save",
binder.writeBean(person);
// A real application would also save the updated person
// using the application's backend
- } catch (BindingException e) {
+ } catch (ValidationException e) {
Notification.show("Person could not be saved, " +
"please check error messages for each field.");
}
diff --git a/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java b/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java
index f36a357617..e0b8330ccc 100644
--- a/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java
+++ b/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java
@@ -66,6 +66,11 @@ public class BinderBookOfVaadinTest {
title = origin.title;
}
+ public BookPerson(String name, int yearOfBirth) {
+ lastName = name;
+ this.yearOfBirth = yearOfBirth;
+ }
+
public String getLastName() {
return lastName;
}
@@ -849,6 +854,31 @@ public class BinderBookOfVaadinTest {
Assert.assertFalse(saveButton.isEnabled());
}
+ @Test
+ public void writeBean_throwsValidationException_bookExampleShouldCompile() {
+ // The person to edit
+ // Would be loaded from the backend in a real application
+ BookPerson person = new BookPerson("John Doe", 1957);
+
+ // Updates the value in each bound field component
+ binder.readBean(person);
+
+ Button saveButton = new Button("Save", event -> {
+ try {
+ binder.writeBean(person);
+ // A real application would also save the updated person
+ // using the application's backend
+ } catch (ValidationException e) {
+ Notification.show("Person could not be saved, "
+ + "please check error messages for each field.");
+ }
+ });
+
+ // Updates the fields again with the previously saved values
+ Button resetButton = new Button("Reset",
+ event -> binder.readBean(person));
+ }
+
private void verifyEventIsFired(AtomicBoolean flag) {
Assert.assertTrue(flag.get());
flag.set(false);