BaseCustomComponent extends DefaultVerticalLayout implements Buildable { protected Span constructLabel(Object entity, AttributeModel attributeModel) { Object value = ClassUtils.getFieldValue(entity, attributeModel.getName()); String formatted = FormatUtils.formatPropertyValue(getEntityModelFactory(), attributeModel, value, ", "); return new Span(formatted == null ? "" : formatted); }    }
@Test public void test() { EntityModel<TestEntity> model = factory.getModel(TestEntity.class); DecimalFormatSymbols sym = DecimalFormatSymbols.getInstance(new Locale("nl")); TestEntity e = new TestEntity("Kevin", 12L); e.setDiscount(BigDecimal.valueOf(12.34)); e.setBirthDate(DateUtils.createLocalDate("04052016")); e.setBirthWeek(DateUtils.createLocalDate("04052016")); e.setSomeInt(1234); e.setSomeTime(LocalTime.of(14, 25, 37)); e.setSomeEnum(TestEnum.A); e.setSomeBoolean(Boolean.TRUE); e.setSomeBoolean2(Boolean.TRUE); TestEntity2 te2 = new TestEntity2(); te2.setName("Bob"); te2.setId(2); e.addTestEntity2(te2); TestEntity2 te3 = new TestEntity2(); te3.setName("Stuart"); te3.setId(3); e.addTestEntity2(te3); Span text = (Span) component.constructLabel(e, model.getAttributeModel("name")); assertEquals("Kevin", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("someInt")); assertEquals("1" + sym.getGroupingSeparator() + "234", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("age")); assertEquals("12", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("discount")); assertEquals("12" + sym.getDecimalSeparator() + "34", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("birthDate")); assertEquals("04/05/2016", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("birthWeek")); assertEquals("2016-18", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("someTime")); assertEquals("14:25:37", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("someEnum")); assertEquals("Value A", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("testEntities")); assertEquals("Bob, Stuart", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("someBoolean")); assertEquals("true", text.getText()); text = (Span) component.constructLabel(e, model.getAttributeModel("someBoolean2")); assertEquals("On", text.getText()); }