How to know if a field of form is edited or not ? Is there any method in java ? The UI is built with vaadin

Viewed 55

How to know if a field of the form is edited or not? Is there any method in java? The UI is built with vaadin. I want to throw an error if a field is not edited, I can throw error I just want an answer how can we check if the field is edited or not using java?

1 Answers

If you have a form and use Binder to bind the fields with the bean, there is a mechanism in Binder that is tracking this and you can use Binder#hasChanges() method to check there is one or more field in the form that has pending changes.

In case your use case is actually to verify that a mandatory field has been entered, you should use asRequired(..) validator to validate that the input is not null / not empty.

If your bean has non-null / non-empty default value, which should be altered, you can use validator that checks the input value is not the default value.

Related