Intercept binder changes

Hi guys, I am using vaadin 8 and to bind model to interface I use binder.
For example:

Binder<Clazz> binder = new Binder<>(Clazz.class);

Then I overrided the method beforeLeave (of View), and I would check in this method is the user have changed something on the interface.

For now I found a “shitty” solution, in my opinion. I have a global variable “modified” set to false, initially.
Then I added to binder the addValueChangeListener, where I set “modified” to true, as the follow:

binder.addValueChangeListener(event -> {
            if (!modified) {
                modified = true;
            }
        });

In the end I check the “modified” variable, to show a message which informs the user, that some changes have been detected…

There is a clean way, to do the same thing?

Thanks!

Hi,

Would Binder’s method hasChanges(), which checks for uncommitted changes in the bould fields, be a solution for your case? From Binder docs:
https://vaadin.com/api/8.1.6/com/vaadin/data/Binder.html#hasChanges–

BR, Katri

thank you!
It worked fine!

great!

Glad to hear that you found it helpful! :slight_smile:

BR, Katri