T
- the generic value of the source observable.public class FunctionBasedValidator<T> extends Object implements Validator
Validator
implementation uses functions to validate the values of an observable. You need to define a
observable value as source that contains the value that should be validated.
There are two "flavours" of using this validator: Using a Predicate
or a Function
for validation.
The variant with Predicate is used for simple use cases where you provide a predicate that simply tells the
validator, if the given value is valid or not. If it is invalid, the given ValidationMessage
will be present
in the ValidationStatus
of this validator.
The variant with Function is used for use cases where different messages should be shown under specific conditions.
Instead of only returning true
or false
the function has to return a
ValidationMessage
for a given input value if it is invalid. The returned message will then be present in the
validation status. If the input value is valid and therefore no validation message should be shown, the function has
to return null
instead.
For more complex validation logic like cross field validation you can use the ObservableRuleBasedValidator
as
an alternative.
Constructor and Description |
---|
FunctionBasedValidator(javafx.beans.value.ObservableValue<T> source,
java.util.function.Function<T,ValidationMessage> function)
Creates a validator that uses a
Function for validation. |
FunctionBasedValidator(javafx.beans.value.ObservableValue<T> source,
java.util.function.Predicate<T> predicate,
ValidationMessage message)
Creates a validator that uses a
Predicate for validation. |
Modifier and Type | Method and Description |
---|---|
ValidationStatus |
getValidationStatus()
Returns the validation status of this validator.
|
public FunctionBasedValidator(javafx.beans.value.ObservableValue<T> source, java.util.function.Function<T,ValidationMessage> function)
Function
for validation. The function has to return a
ValidationMessage
for a given input value or null
if the value is valid.source
- the observable value that will be validated.function
- the validation function.public FunctionBasedValidator(javafx.beans.value.ObservableValue<T> source, java.util.function.Predicate<T> predicate, ValidationMessage message)
Predicate
for validation. The predicate has to return true
if the input value is valid. Otherwise false
.
When the predicate returns false
, the given validation message will be used.
source
- the observable value that will be validated.predicate
- the validation predicate.message
- the message that will be used when the predicate doesn't matchpublic ValidationStatus getValidationStatus()
Validator
getValidationStatus
in interface Validator
Copyright © 2015 Saxonia Systems AG. All rights reserved.