aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/datamodel
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2016-10-12 15:52:38 +0300
committerPekka Hyvönen <pekka@vaadin.com>2016-10-13 06:08:37 +0000
commitb66631c3dc5d79caa6a78274d2ea4107ccae7973 (patch)
tree13d58756d17d0888250dcbf75874af4e90879a38 /documentation/datamodel
parent8bdab4dc32d4c25b7f0bb5457c76234185ad6368 (diff)
downloadvaadin-framework-b66631c3dc5d79caa6a78274d2ea4107ccae7973.tar.gz
vaadin-framework-b66631c3dc5d79caa6a78274d2ea4107ccae7973.zip
Fix BoV custom ValidationStatusHandler example
Change-Id: I94d82a6200197a6d9f6b31d66153a140333b5b1e
Diffstat (limited to 'documentation/datamodel')
-rw-r--r--documentation/datamodel/datamodel-forms.asciidoc10
1 files changed, 8 insertions, 2 deletions
diff --git a/documentation/datamodel/datamodel-forms.asciidoc b/documentation/datamodel/datamodel-forms.asciidoc
index 8772f0d770..0a040230c6 100644
--- a/documentation/datamodel/datamodel-forms.asciidoc
+++ b/documentation/datamodel/datamodel-forms.asciidoc
@@ -563,14 +563,20 @@ We can also define our own status handler to provide a custom way of handling st
[source, java]
----
+// We will first set the status label's content mode to HTML
+// in order to display generated error messages separated by a <br> tag
+formStatusLabel.setContentMode(ContentMode.HTML);
+
BinderValidationStatusHandler defaultHandler = binder.getValidationStatusHandler();
binder.setValidationStatusHandler(status -> {
// create an error message on failed bean level validations
List<Result<?>> errors = status.getBeanValidationErrors();
+ // collect all bean level error messages into a single string,
+ // separating each message with a <br> tag
String errorMessage = errors.stream().map(Result::getMessage)
- .map(o -> o.get()).collect(Collectors.joining("\n"));
- // show error in a label
+ .map(o -> o.get()).collect(Collectors.joining("<br>"));
+ // finally, display all bean level validation errors in a single label
formStatusLabel.setValue(errorMessage);
formStatusLabel.setVisible(!errorMessage.isEmpty());