Is it possible to get all the ErrorLevel.WARNING from a Binder object? I know that
binder.validate().getFieldValidationErrors();
Can get me all of the validation ErrorLevel.ERROR, but I want a way to display all of the warnings as well. Basically in Vaaddin 7 we used the setInvalidAllowed(true) in order to allow users to save a form while invalid so they could start it and then come back later before moving it forward. I converted to the new Binder and have all the new validators working, however there is no similiar setInvalidAllow method I know of and I cannot replicate the functionality. My though was to change all my new Validator Code to create warnings instead of errors and I could just that the warnings were empty in order to push forward while still allowing them to save with some invalid data. After setting them all to
return ValidationResult.create("Error Text Here", ErrorLevel.WARNING);
I don’t know anyway to get a list of all of them. They are showing as warnings in the UI side as expected and allow the saving, but I need a way to capture them. Is this possible?
Thanks for the response. My validations are at the field level so I don’t believe they will be picked up in Bean Validations. I spend most of the day looking at the code that does the validation, in particular validateBindings() in Binder validate process. To me it looks like it removes the messages of anything that is not at the ERROR level during BindingImpl::doValidation. Do you know of anyway to get the field level warnings?
I am creating custom fields and then when I bind I am doing .withValidator(... . Maybe that does not matter in this case, however when I do what you suggested it still only picks up validators that return ValidationResult.error and not ones that return ValidationResult.create("warn message, ErrorLevel.WARNING)"
All warnings are gone. After looking at the internal code when they create the ValidationResult, if it is not an ERROR they do not pass the message to the result so you lose the information when you get to that point…
ValidationResultWrap(R value, ValidationResult result) {
if (result.isError()) {
wrappedResult = new SimpleResult<>(null, result.getErrorMessage());
} else {
wrappedResult = new SimpleResult<>(value, null); // Message is not passed at this point
}
this.resultList = new ArrayList<>();
this.resultList.add(result);
}
For now I am extending the Binder to get access to getBindings() and doing the following which prints the warnings: