Search in sources :

Example 1 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class ForTemplateView method updateModelItem.

private void updateModelItem(StateNode stateNode, String text, String key) {
    ModelMap model = ModelMap.get(stateNode);
    model.setValue("text", text);
    model.setValue("key", key);
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap)

Example 2 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class BeanModelTypeTest method modelToApplication.

@Test
public void modelToApplication() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    model.setValue("string", "3");
    model.setValue("intValue", Integer.valueOf(3));
    Bean bean = beanType.modelToApplication(model.getNode());
    Assert.assertEquals("3", bean.getString());
    Assert.assertEquals(3, bean.getIntValue());
    Assert.assertNull(bean.getIntObject());
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 3 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class BeanModelTypeTest method applicationToModel_filtered.

@Test
public void applicationToModel_filtered() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, new PropertyFilter(name -> !name.equals("intValue")));
    Bean bean = new Bean(3);
    StateNode applicationToModel = beanType.applicationToModel(bean, new PropertyFilter(name -> name.equals("string") || name.equals("intValue")));
    ModelMap model = ModelMap.get(applicationToModel);
    Assert.assertEquals(Arrays.asList("string"), model.getKeys().collect(Collectors.toList()));
    Assert.assertEquals("3", model.getValue("string"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 4 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class BeanModelTypeTest method importBean_incompatibleBean.

@Test(expected = IllegalArgumentException.class)
public void importBean_incompatibleBean() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    DifferentBean bean = new DifferentBean(3);
    beanType.importProperties(model, bean, PropertyFilter.ACCEPT_ALL);
}
Also used : ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Example 5 with ModelMap

use of com.vaadin.flow.internal.nodefeature.ModelMap in project flow by vaadin.

the class BeanModelTypeTest method importBean_withImportFilter.

@Test
public void importBean_withImportFilter() {
    BeanModelType<Bean> beanType = new BeanModelType<>(Bean.class, PropertyFilter.ACCEPT_ALL);
    ModelMap model = ModelMap.get(new StateNode(ModelMap.class));
    Bean bean = new Bean(3);
    beanType.importProperties(model, bean, new PropertyFilter(name -> "intObject".equals(name)));
    Assert.assertEquals(1, model.getKeys().count());
    Assert.assertEquals(Integer.valueOf(3), model.getValue("intObject"));
}
Also used : PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Arrays(java.util.Arrays) StateNode(com.vaadin.flow.internal.StateNode) Date(java.util.Date) Test(org.junit.Test) Bean(com.vaadin.flow.templatemodel.Bean) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) PropertyFilter(com.vaadin.flow.templatemodel.PropertyFilter) Bean(com.vaadin.flow.templatemodel.Bean) Test(org.junit.Test)

Aggregations

ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)41 Test (org.junit.Test)30 StateNode (com.vaadin.flow.internal.StateNode)18 Bean (com.vaadin.flow.templatemodel.Bean)18 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)9 ModelType (com.vaadin.flow.templatemodel.ModelType)5 PropertyFilter (com.vaadin.flow.templatemodel.PropertyFilter)5 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 Assert (org.junit.Assert)5 Arrays (java.util.Arrays)4 Date (java.util.Date)4 BeanContainingBeans (com.vaadin.flow.templatemodel.BeanContainingBeans)3 InvalidTemplateModelException (com.vaadin.flow.templatemodel.InvalidTemplateModelException)3 ReflectTools (com.vaadin.flow.internal.ReflectTools)2 NodeChange (com.vaadin.flow.internal.change.NodeChange)2 BasicModelType (com.vaadin.flow.templatemodel.BasicModelType)2 Serializable (java.io.Serializable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClassList (com.vaadin.flow.dom.ClassList)1