]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix Binder documentation on ValidationException (#8949)
authorPekka Hyvönen <pekka@vaadin.com>
Mon, 27 Mar 2017 13:04:35 +0000 (16:04 +0300)
committerHenri Sara <henri.sara@gmail.com>
Mon, 27 Mar 2017 13:04:35 +0000 (16:04 +0300)
documentation/datamodel/datamodel-forms.asciidoc
server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java

index 3db83d64367a2bc08e66ae3087467181663ef24d..a565e2ed01d4791f98f21e5fa27fd4088f385e48 100644 (file)
@@ -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.");
     }
index f36a357617c3981ed6b7265c90ac7e3422028dc9..e0b8330ccc84c8f7a9c2013a22cbe66e2c135d22 100644 (file)
@@ -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);