RE: Bean level validation with grid in line editor - Cannot validate error

The cross field validation with BeanValidator is not yet supported

I’m using Vaadin 8.2 with a grid and the integrated editor.
I’m using several validators on field level, which is working fine.
Now I need a cross field validation. So I created a custom bean level validator and
I’m using it in the following way:


In runtime I get the following error:
java.lang.IllegalStateException: Cannot validate binder: bean level validators have been configured but no bean is currently set

By using the inline editor, the bean should be handled implicit - what am I doing wrong?

I was on the Dev Day in Hamburg where it was presented. So it should be supported. Maybe it is a bug in combination with the inline editor?

Now my cross field validation works.
The errormessage says, that no bean was set. So I call setBean by opening the editor:
grid.getEditor().addOpenListener(event → grid.getEditor().getBinder().setBean(event.getBean()));

In my case it is working perfect.
Or does someone see a problem with it?

I’ll try some explanation (long, for short answer you can jump to the last paragraph :D)

By default, grid editor is in buffered mode, if you modify your input then your bean property is not modified.
Grid editor save method always use this.binder.validate(). (see here )

And validate method in the binder throws an error if bean is not “set” (buffered mode bean use readBean not setBean):
You can see in the binder class:

if (getBean() == null && !validators.isEmpty()) {
throw new IllegalStateException("Cannot validate binder: "
+ "bean level validators have been configured "
+ "but no bean is currently set");

In the javadoc it’s wrong (see here )

If all field level validators pass, and setBean(Object) has been used to bind to a bean, bean level validators are run for that bean. Bean level validators are ignored if there is no bound bean or if any field level validator fails.

I don’t know why still use validate before writeBeanIfValid, some bugs should have been corrected in Vaadin 8.2 and in my opnion it’s only a old workaround (before 8.2). (see here and )

Your workaround may cause some problems because you use setBean in a buffered mode. (perhaps your bean properties will be updated …). If you can use unbuffered mode then use it and that should be ok.