diff options
author | dunand <jeffnadeau@gmail.com> | 2017-05-08 01:52:15 -0400 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-05-08 08:52:15 +0300 |
commit | 70d5940893075be7afb268b52904825cf55c1460 (patch) | |
tree | 775d1fb3db684b95c825eedb0bb4ca46ddfcbdd6 /documentation/components | |
parent | 594cabd5f859bb66eebf16491a41ccd2f7d527cc (diff) | |
download | vaadin-framework-70d5940893075be7afb268b52904825cf55c1460.tar.gz vaadin-framework-70d5940893075be7afb268b52904825cf55c1460.zip |
Update example to Vaadin 8 (#9260)
Replaced Result<String> with ValidationResult.
Replaced variable input by value.
Removed first phrase after example since it does not make sense anymore.
Diffstat (limited to 'documentation/components')
-rw-r--r-- | documentation/components/components-fields.asciidoc | 12 |
1 files 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<String> { @Override - public Result<String> 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. |