DateField Listener

Hi
Can you please help How can I set up a DateField listener?

Hi!
You can do in in two ways:

  1. Define an ItemPropertyChangeListener for a datasource if the dateField is bounded to the datasource
  2. Define a listener for the UI component
The example below illustrates both approaches:

package com.company.datefieldlistener.web.party;

import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.datefieldlistener.entity.Party;
import com.haulmont.cuba.gui.components.DateField;
import com.haulmont.cuba.gui.data.Datasource;

import javax.inject.Inject;
import javax.inject.Named;

public class PartyEdit extends AbstractEditor<Party> {

    @Named("fieldGroup.endDate")
    private DateField endDateField;

    @Inject
    private Datasource<Party> partyDs;

    @Override
    protected void postInit() {
        super.postInit();

        partyDs.addItemPropertyChangeListener(e -> {
            if ("startDate".equals(e.getProperty())) {
                showNotification("startDate changed to " + e.getValue(), NotificationType.HUMANIZED);
            }
        });

        endDateField.addValueChangeListener(e -> {
            showNotification("endDate changed to " + e.getValue(), NotificationType.HUMANIZED);
        });
    }
}

DateFieldListener.zip (79.6K)