diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2016-09-12 12:05:19 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-09-12 13:07:22 +0000 |
commit | 28f5c845793be9a0db3f2acef914a68ccc91ce80 (patch) | |
tree | 42ba7c5cffc7de3a2412ffbd3cc6fa3605ddb606 /documentation/datamodel | |
parent | 363dce92ae948aa7912007bb024c980de820851f (diff) | |
download | vaadin-framework-28f5c845793be9a0db3f2acef914a68ccc91ce80.tar.gz vaadin-framework-28f5c845793be9a0db3f2acef914a68ccc91ce80.zip |
Refactor Binder Status Handling API
BinderStatusHandler is now triggered only once per validation.
Unified ValidationError and BinderResult into BinderValidationStatus.
Renamed ValidationStatusChangeEvent into ValidationStatus.
Unified handler names for validation status.
Next patch will fix resetting of field errors on reset.
Change-Id: I9536d554d781fe599fbd7e5bcb5a9ffebe675ca0
Diffstat (limited to 'documentation/datamodel')
-rw-r--r-- | documentation/datamodel/datamodel-forms.asciidoc | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/documentation/datamodel/datamodel-forms.asciidoc b/documentation/datamodel/datamodel-forms.asciidoc index 62fd9df38c..62d844dee6 100644 --- a/documentation/datamodel/datamodel-forms.asciidoc +++ b/documentation/datamodel/datamodel-forms.asciidoc @@ -323,11 +323,11 @@ Even if the user has not edited a field, all validation error will be shown if w binder.load(new Person()); // This will make all current validation errors visible -List<ValidationError<?>> validationErrors = binder.validate(); +ValidationStatus<Person> status = binder.validate(); -if (!validationErrors.isEmpty()) { +if (status.hasErrors()) { Notification.show("Validation error count: " - + validationErrors.size()); + + status.getValidationErrors().size()); } ---- @@ -341,7 +341,7 @@ Handling a checked exception:: ---- try { binder.save(person); -} catch (BindingException e) { +} catch (ValidationException e) { Notification.show("Validation error count: " + e.getValidationErrors().size()); } @@ -566,21 +566,17 @@ We can also define our own status handler to provide a custom way of handling st ---- BinderStatusHandler defaultHandler = binder.getStatusHandler(); -binder.setStatusHandler(results -> { - String errorMessage = results.stream() - // Ignore helper and confirmation messages - .filter(BinderResult::isError) - // Ignore messages that belong to a specific field - .filter(error -> !error.getField().isPresent()) - // Create a string out of the remaining messages - .map(Result::getMessage).map(o -> o.get()) - .collect(Collectors.joining("\n")); - - formStatusLabel.setValue(errorMessage); - formStatusLabel.setVisible(!errorMessage.isEmpty()); - - // Let the default handler show messages for each field - defaultHandler.accept(event); +binder.setStatusHandler(status -> { + // create an error message on failed bean level validations + List<Result<?>> errors = status.getBeanValidationErrors(); + String errorMessage = errors.stream().map(Result::getMessage) + .map(o -> o.get()).collect(Collectors.joining("\n")); + // show error in a label + formStatusLabel.setValue(errorMessage); + formStatusLabel.setVisible(!errorMessage.isEmpty()); + + // Let the default handler show messages for each field + defaultHandler.accept(status); }); ---- |