ConvertUtils { public static Object convertToPresentationValue(AttributeModel am, Object input) { if (input == null) { return null; } Locale locale = VaadinUtils.getLocale(); boolean grouping = SystemPropertyUtils.useThousandsGroupingInEditMode(); boolean percentage = am.isPercentage(); if (am.isWeek()) { LocalDateWeekCodeConverter converter = new LocalDateWeekCodeConverter(); return converter.convertToPresentation((LocalDate) input, new ValueContext(locale)); } else if (NumberUtils.isInteger(am.getType())) { return VaadinUtils.integerToString(grouping, percentage, (Integer) input); } else if (NumberUtils.isLong(am.getType())) { return VaadinUtils.longToString(grouping, percentage, (Long) input); } else if (NumberUtils.isDouble(am.getType())) { return VaadinUtils.doubleToString(am.isCurrency(), am.isPercentage(), grouping, am.getPrecision(), (Double) input, locale); } else if (BigDecimal.class.equals(am.getType())) { return VaadinUtils.bigDecimalToString(am.isCurrency(), am.isPercentage(), grouping, am.getPrecision(), (BigDecimal) input, locale); } return input; } private  ConvertUtils(); static Object convertToPresentationValue(AttributeModel am, Object input); static Result<? extends Object> convertToModelValue(AttributeModel am, Object value); @SuppressWarnings("unchecked") static Collection<T> convertCollection(Object value, AttributeModel am);  }
@Test public void testConvertToPresentationValue() { EntityModel<TestEntity> model = emf.getModel(TestEntity.class); Object s = ConvertUtils.convertToPresentationValue(model.getAttributeModel("age"), 12L); assertEquals("12", s); s = ConvertUtils.convertToPresentationValue(model.getAttributeModel("discount"), BigDecimal.valueOf(17.79)); assertEquals("17,79", s); s = ConvertUtils.convertToPresentationValue(model.getAttributeModel("id"), 1234); assertEquals("1234", s); s = ConvertUtils.convertToPresentationValue(model.getAttributeModel("birthWeek"), DateUtils.createLocalDate("01022015")); assertEquals("2015-05", s); s = ConvertUtils.convertToPresentationValue(model.getAttributeModel("someDouble"), 1234.56); assertEquals("1234,56", s); }
@Test public void testConvertToPresentationDates() { EntityModel<TestEntity> model = emf.getModel(TestEntity.class); Object s = ConvertUtils.convertToPresentationValue(model.getAttributeModel("birthDate"), LocalDate.of(2014, 1, 1)); assertEquals("01-01-2014", ((LocalDate) s).format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))); s = ConvertUtils.convertToPresentationValue(model.getAttributeModel("registrationTime"), LocalDateTime.of(2014, 1, 1, 13, 14, 0)); assertEquals("2014-01-01T13:14", s.toString()); }