how to identify, if in any control, user changes values

in a view I display a form with many controls
if a user change values in one or more controls, and the user try to exit without saving . I want to show a message asking if he want to save before exit

is a way to identify, if in any control, user changes values (without compare manually, in each control, initial vs actual value)
thanks for any help

Fidel Lagos

Hi Fidel,
If you are using Vaadin 8 I think Binder is what you need. Take a look at https://vaadin.com/docs/-/part/framework/datamodel/datamodel-forms.html

You can use Binder.hasChanges to check if some field has uncomitted data or use a listener (Binder.addValueChangeListener) to track changes

HTH
Marco

Hi Marco
Thank for your anwer

I am using vaadin 7 ( BeanItemContainer and fieldgroups )

there is a equivalent method in vaadin 7

thanks again

Hi,
first of all sorry for late response.
In Vaadin 7 FieldGroup has a isModifed mehod but I think you need some custom code to listen to field changes.
For example you could call FieldGroup.getFields() and for each field attach the same ValueChangeListener that checks for FieldGroup.isModified().
Or you can can extend FieldGroup (or BeanFieldGroup) and override configureField method to add the ValueChangeListener listener.

Or you can use MBeanFieldGroup from Viritin addon on which you can attach a FieldGroupListener (MBeanFieldGroup.withEagerValidation(listener)) that is invoked every time a field value changes (like described above)

HTH
Marco