You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Method to get bean level BinderValidationStatus when using read/writeBean #13393
I'm using vaadin 22 with a form that uses read/writeBean.
I'm trying to add cross field validation to the binder:
binder.withValidator(new Validator<DiscountCode>()
{
@Override
public ValidationResult apply(DiscountCode value, ValueContext context)
{
if (bad) return false;
return ValidationResult.ok();
}
});
If I call binder.writeBeanIfValid it returns false (as expected) when bad is true.
The problem is that I need to get the BinderValidationStatus list when writeBeanIfValid returns false.
The only way I can see to get the list of status' is via a call to binder.validate.
The problem is that binder.validate throws the following exception:
java.lang.IllegalStateException: Cannot validate binder: bean level validators have been configured but no bean is currently set
at com.vaadin.flow.data.binder.Binder.validate(Binder.java:2479) ~[flow-data-9.0.8.jar:9.0.8]
at com.vaadin.flow.data.binder.Binder.validate(Binder.java:2463) ~[flow-data-9.0.8.jar:9.0.8]
at dev.onepub.ui.crud.editor.EditorFormLayout.saveEdits(EditorFormLayout.java:75) ~[classes/:?]
at dev.onepub.ui.crud.editor.EditorLayout.saveEdits(EditorLayout.java:132) ~[classes/:?]
I can't use setBean as I don't want the form to automatically write to the bean.
Hopefully I've missed something and this feature already exists but I've been through the binder source code and can't see a path.
Describe the solution you'd like
Add a variation of validate that allows a bean to be passed.
binder.validate(bean);
Describe alternatives you've considered
Overloading the binder.getBean and returning a bean during the validation call when it calls getBean
Did you tried with Binder.setValidationStatusHandler(...) ? It is invoked at the end of writeBeanIfValid() and it gets as input a BinderValidationStatus<BEAN>.
Can this help with your use case?
This ticket is being closed due to inactivity. Please provide your feedback in a comment, so we can proceed with it, or create a new ticket if this issue is still actual for you.
Activity
vaadin-bot commentedon Mar 29, 2022
Thanks for using Vaadin! We appreciate your help and we’ll take care of this as soon as possible.
mcollovati commentedon Mar 30, 2022
Did you tried with
Binder.setValidationStatusHandler(...)? It is invoked at the end ofwriteBeanIfValid()and it gets as input aBinderValidationStatus<BEAN>.Can this help with your use case?
mshabarov commentedon May 9, 2022
This ticket is being closed due to inactivity. Please provide your feedback in a comment, so we can proceed with it, or create a new ticket if this issue is still actual for you.