EntityModelUtils { public static <T> String getDisplayPropertyValue(Collection<T> entities, EntityModel<T> model, int maxItems, MessageService messageService, Locale locale) { String property = model.getDisplayProperty(); StringBuilder result = new StringBuilder(); int i = 0; for (T t : entities) { if (result.length() > 0) { result.append(", "); } if (i < maxItems) { result.append(ClassUtils.getFieldValueAsString(t, property)); } else { result.append(messageService.getMessage("ocs.and.others", locale, entities.size() - maxItems)); break; } i++; } return result.toString(); } private  EntityModelUtils(); static void copySimpleAttributes(T source, T target, EntityModel<T> model, String... ignore); static String getDisplayPropertyValue(Collection<T> entities, EntityModel<T> model, int maxItems,
			MessageService messageService, Locale locale); static String getDisplayPropertyValue(T entity, EntityModel<T> model); static final Set<String> ALWAYS_IGNORE; }
@Test public void testGetDisplayPropertyValue() { EntityModel<TestEntity> model = factory.getModel(TestEntity.class); TestEntity entity = new TestEntity(); entity.setName("test name"); String value = EntityModelUtils.getDisplayPropertyValue(entity, model); assertEquals("test name", value); }
@Test public void testGetDisplayPropertyValue2() { EntityModel<TestEntity> model = factory.getModel(TestEntity.class); TestEntity entity = new TestEntity(); entity.setName("test name"); TestEntity entity2 = new TestEntity(); entity2.setName("test name 2"); String value = EntityModelUtils.getDisplayPropertyValue(Lists.newArrayList(entity, entity2), model, 2, messageService, Locale.ENGLISH); assertEquals("test name, test name 2", value); }
@Test public void testGetDisplayPropertyValue3() { EntityModel<TestEntity> model = factory.getModel(TestEntity.class); TestEntity entity = new TestEntity(); entity.setName("test name"); TestEntity entity2 = new TestEntity(); entity2.setName("test name 2"); TestEntity entity3 = new TestEntity(); entity3.setName("test name 3"); String value = EntityModelUtils.getDisplayPropertyValue(Lists.newArrayList(entity, entity2, entity3), model, 2, messageService, Locale.ENGLISH); assertEquals("test name, test name 2, ocs.and.others", value); }