My understanding on how to achieve getting a list of strings and displaying on a table.
any observations?
/***
*
* List -> List (Key value entity allows dynamically to add and remove n amount of properties)
* List -> keyValueCollectionContainer (KeyValue Collection is what is bound to the table)
* keyValueEntitiesTable <- Dynamically add columns from the properties of the KeyValueCollectionContainer
*/
@Subscribe
public void onInit(InitEvent event) {
//GET LIST OF STRINGS
List<String> names = happyService.getList();
//CREATE LIST KEY VALUE ENTITIES THAT WILL CONTAIN THESE STRINGS
List<KeyValueEntity> keyValueEntities = new ArrayList<>();
//ADD DYNAMIC PROPERTY TO CONTAINER
keyValueCollectionContainer.addProperty("Name", String.class);
//ADD COLUMN FROM CONTAINER PROPERTY
MetaClass entityMetaClass = keyValueCollectionContainer.getEntityMetaClass();
keyValueEntitiesTable.addColumn(new Table.Column(entityMetaClass.getPropertyPath("Name")));
//LOOP THROUGH LIST AND ADD TO KEY VALUE ENTITY
names.stream().forEach(s -> {
KeyValueEntity keyValueEntity = new KeyValueEntity();
keyValueEntity.setValue("Name", s);
keyValueEntities.add(keyValueEntity);
});
//ADD ALL ENTITIES TO THE COLLECTION CONTAINER
keyValueCollectionContainer.setItems(keyValueEntities);
}
keyvaluecontainer.zip (85.9 KB)