Search in sources :

Example 6 with DateField

use of com.haulmont.cuba.gui.components.DateField in project cuba by cuba-platform.

the class DateFieldDsTest method testUnsubscribeDsListener.

@Test
public void testUnsubscribeDsListener() {
    DateField dateField = (DateField) factory.createComponent(DateField.NAME);
    Datasource<User> userDs = getTestUserDatasource();
    User user = userDs.getItem();
    Date updateTs = new Date();
    user.setUpdateTs(updateTs);
    dateField.setDatasource(userDs, "updateTs");
    // unbind
    dateField.setDatasource(null, null);
    Datasource.ItemPropertyChangeListener<User> propertyChangeListener = e -> {
        throw new RuntimeException("Value was changed externally");
    };
    userDs.addItemPropertyChangeListener(propertyChangeListener);
    dateField.setValue(new Date());
    assertEquals(updateTs, user.getUpdateTs());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) DateField(com.haulmont.cuba.gui.components.DateField) Datasource(com.haulmont.cuba.gui.data.Datasource) Ignore(org.junit.Ignore) Date(java.util.Date) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Component(com.haulmont.cuba.gui.components.Component) User(com.haulmont.cuba.security.entity.User) Assert.assertEquals(org.junit.Assert.assertEquals) User(com.haulmont.cuba.security.entity.User) DateField(com.haulmont.cuba.gui.components.DateField) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DateField (com.haulmont.cuba.gui.components.DateField)6 User (com.haulmont.cuba.security.entity.User)6 Date (java.util.Date)6 Test (org.junit.Test)6 Component (com.haulmont.cuba.gui.components.Component)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Ignore (org.junit.Ignore)5