This validator allows to specify the conditions to be met as Constraints,
and also allows to add other MFXValidators as dependencies, meaning that
the validator will be valid only when all its constraints are valid and all its dependencies
are also valid.
setOnUpdated(BiConsumer)
action performed when the update() method is triggered.
You have two ways of querying the validator's state:
One is to simply query the validProperty()
The other is to call validate()
-
Property Summary
Properties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconstraint(Constraint constraint) Adds the givenConstraintto the validator's constraint list.constraint(Severity severity, String message, BooleanExpression condition) Creates aConstraintwith the given parameters, then callsconstraint(Constraint).constraint(String message, BooleanExpression condition) Creates aConstraintwith ERROR severity and the given message and condition, then callsconstraint(Constraint).dependsOn(MFXValidator validator) Adds the givenMFXValidatordependency to this validator.booleanbooleanbooleanisValid()protected voidThis is called when theupdate()method is triggered and it's responsible for running the action specified by the user,setOnUpdated(BiConsumer).removeConstraint(Constraint constraint) Removes the givenConstraintfrom the validator.removeDependency(MFXValidator validator) Removes the given validator dependency from this validator.setFailFast(boolean failFast) Sets whether thevalidate()method should fail fast.setOnUpdated(BiConsumer<Boolean, List<Constraint>> onUpdated) Allows to specify the action to perform every time theupdate()method is triggered.setSortBySeverity(boolean sortBySeverity) Allows to specify whether to sort the invalid constraints list by severity when callingvalidate().protected voidsetValid(boolean valid) Sets the value of the property valid.voidupdate()This is the method responsible for updating the validator' state.validate()This method queries all the validator's dependencies and constraints to build a list containing all the unmet constraints.Callsvalidate()then chains all the invalid constraints' messages into a String.Specifies the validator' state.
-
Property Details
-
valid
Specifies the validator' state. This is given by chaining all the validator's dependencies and constraints.- See Also:
-
-
Constructor Details
-
MFXValidator
public MFXValidator()
-
-
Method Details
-
constraint
Adds the givenConstraintto the validator's constraint list.Also adds an
The listener is build using the newInvalidationListenerto the constraint's condition to trigger theupdate()method when it changes. This is needed to automatically update thevalidProperty().Whenconstruct. -
constraint
Creates aConstraintwith the given parameters, then callsconstraint(Constraint). -
constraint
Creates aConstraintwith ERROR severity and the given message and condition, then callsconstraint(Constraint). -
removeConstraint
Removes the givenConstraintfrom the validator.Also invokes
When.disposeFor(ObservableValue)on the constraint's condition (seeconstraint(Constraint)andWhen). -
dependsOn
Adds the givenMFXValidatordependency to this validator.Also adds an
InvalidationListenerto the dependencyvalidProperty()to trigger theupdate()method when it changes. This is needed to automatically update thevalidProperty() -
removeDependency
Removes the given validator dependency from this validator.Also calls
When.disposeFor(ObservableValue)on the dependency's valid property (seedependsOn(MFXValidator)andWhen). -
validate
This method queries all the validator's dependencies and constraints to build a list containing all the unmet constraints.If the list is not empty then the validator' state is invalid.
The list can also be sorted by constraint severity by settingsetSortBySeverity(boolean)to true. The method can be also set to "fail fast" meaning that we do not care about all the invalid conditions but it's also enough to get the first one. This applies to both dependencies and constraints. In this case the sorting is ignored of course since the list will always contain at most one constraint. -
update
public void update()This is the method responsible for updating the validator' state. Despite being public it should not be necessary to call it automatically as the constraints and the dependencies automatically trigger this method.Note that constraints are evaluated in order of insertion and according to their
At the end invokesConstraint.getChainMode(), so be careful with OR modes.onUpdated(). -
validateToString
Callsvalidate()then chains all the invalid constraints' messages into a String. -
onUpdated
protected void onUpdated()This is called when theupdate()method is triggered and it's responsible for running the action specified by the user,setOnUpdated(BiConsumer). -
isValid
public boolean isValid()- Returns:
- whether the validator' state is valid
-
validProperty
Specifies the validator' state. This is given by chaining all the validator's dependencies and constraints.- See Also:
-
setValid
protected void setValid(boolean valid) Sets the value of the property valid.- Property description:
- Specifies the validator' state. This is given by chaining all the validator's dependencies and constraints.
-
getOnUpdated
- Returns:
- the action to perform after an
update() - See Also:
-
setOnUpdated
Allows to specify the action to perform every time theupdate()method is triggered. The action is aBiConsumercarrying the validator' state and the list of invalid constraints (empty if valid of course). -
isSortBySeverity
public boolean isSortBySeverity()- Returns:
- whether the invalid constraints list is sorted by severity
-
setSortBySeverity
Allows to specify whether to sort the invalid constraints list by severity when callingvalidate(). -
isFailFast
public boolean isFailFast()- Returns:
- whether the
validate()method should fail fast
-
setFailFast
Sets whether thevalidate()method should fail fast.
-