Reputation: 11
On a custom processor I have developed I want the property validation to be able to make certain properties optional if another property is set. In other words property "File Name" is only required if property "Engine" is set to "FILE". If property "Engine" is set to "AWS" then property "File Name" is then not required. Even better if there is a way to hide it completely.
I have built over 100 custom processors and have always wanted to include this kind of feature but have yet to find a solution save for building out a custom UI (I have done that too - way too much work).
Upvotes: 1
Views: 399
Reputation: 869
Try implementing customValidate(final ValidationContext validationContext)
in your processor and add the conditional logic that you want here.
Sample code could look something like this
@Override
protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
final Collection<ValidationResult> results = new ArrayList<>();
final String engine = validationContext.getProperty(ENGINE).getValue();
if (FILES.equals(engine)) {
if (!validationContext.getProperty(FILE_NAME).isSet()) {
final String displayName = FILE_NAME.getDisplayName();
results.add(new ValidationResult.Builder()
.subject(displayName)
.explanation(format("'%s' is required to use '%s' listing strategy", displayName, FILES.getDisplayName()))
.valid(false)
.build());
}
}
return results;
}
Upvotes: 4