From 70d5940893075be7afb268b52904825cf55c1460 Mon Sep 17 00:00:00 2001 From: dunand Date: Mon, 8 May 2017 01:52:15 -0400 Subject: [PATCH] Update example to Vaadin 8 (#9260) Replaced Result with ValidationResult. Replaced variable input by value. Removed first phrase after example since it does not make sense anymore. --- documentation/components/components-fields.asciidoc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/documentation/components/components-fields.asciidoc b/documentation/components/components-fields.asciidoc index c963c96ebe..1415f98e73 100644 --- a/documentation/components/components-fields.asciidoc +++ b/documentation/components/components-fields.asciidoc @@ -156,20 +156,18 @@ whether or not the given input was valid. ---- class MyValidator implements Validator { @Override - public Result apply(String value, ValueContext context) { - if(input.length() == 6) { - return Result.ok(input); + public ValidationResult apply(String value, ValueContext context) { + if(value.length() == 6) { + return ValidationResult.ok(); } else { - return Result.error( + return ValidationResult.error( "Must be exactly six characters long"); } } } ---- -Because [methodname]#Result.ok# takes the valid value as an argument, a validator -can also do some sanitization on valid inputs, such as removing leading and -trailing whitespace from a string. Since [interfacename]#Validator# is a functional +Since [interfacename]#Validator# is a functional interface, you can often simply write a lambda expression instead of a full class declaration. There is also an [methodname]#withValidator# overload that creates a validator from a boolean function and an error message. -- 2.39.5