DateField value change event is not fired correctly on binding

I am using Vaadin 8.1 with SpringBoot 1.4.2
class Person
{
private Date startDate;
private String name;
public Date getStartDate() {return startDate;}
public void setStartDate(Date dt){startDate=dt;}
public String getName(){return name;}
public void setName(String s){name = s;}
}

public class TestUI extends UI
{
@Override
protected void init(VaadinRequest request) {
VerticalLayout vl = new VerticalLayout();
DateField txtStartDate = new DateField(label);
txtStartDate.setPlaceholder(“mm/dd/yyyy”);
txtStartDate.setDateFormat(“mm/dd/yyyy”);
vl.addComponent(txtStartDate);
TextField nameField = new TextField(“Name:”);
vl.addComponent(nameField);

     setContent(vl);

    Binder<Person> personBinder = new Binder<>();
     personBinder .bind(nameField ,Person::getName,Person::setName);
     personBinder .forField(txtStartDate)
        .withNullRepresentation(null)        
        .withConverter(new LocalDateToDateConverter())
        .bind(Person::getStartDate,Person::setStartDate);
     personBinder.addStatusChangeListener(event -> {
        if(event.getBinder().isValid()                     
                && event.getBinder().hasChanges())
            Notification.show("Data was changed!");
    });

}

}

After I change the start date, the change event was not fired.
Did I do something wrong? or using wrong event listener?

Thank you in advance!

Hi,

You are probably using the wrong listener. According to the Javadoc:

The Binder status is changed whenever any of the following happens:

  - if it's bound and any of its bound field or select has been changed
  - writeBean(Object) or writeBeanIfValid(Object) is called
  - readBean(Object) is called
  - setBean(Object) is called
  - removeBean() is called
  - Binder.BindingBuilder.bind(ValueProvider, Setter) is called
  - validate() or Binder.Binding.validate() is called

None of those are happening after you add the listener. I guess what you actually want is to add a
ValueChangeListener
or a
Button
with a
ClickListener
.