Vaadin: when does a binder actually write to a bean?

Viewed 37

I am fighting with Vaadin's binder! I have two issues - here is my first:

When is a binder actually updating the underlying bean?

In my form I have added a "Revert"-button which triggers a binder.readBean(). The intended purpose of which is, that - if a user decides that some change was not good - pushing that button would allow to restore the previous values of the form.

But here - even though binder.writeBean() is never called in the process (I have added log-statements to each call!) the value in the bean has obviously been changed and the binder.readBean() does NOT bring back the previous values! What am I missing here?

My understanding so far was that only once I did a binder.writeBean() the underlying bean is actually updated with the new values. Is that not so?

I am using v23.1.7

1 Answers

To find out when the value is written, you can run your application in debug mode and set a breakpoint in one of the bean's setter methods.

You aren't sharing a minimal reproducible example, but I would guess that the reason for your problems is that you're initially providing the bean to the binder using setBean. When you do that, Binder will update the bean every time a field is changed by the user. If you instead use readBean, then Binder will not directly update the bean but instead wait for an update to be explicitly triggered through writeBean.

Related