Vaadin 8 Grid Dynamic Column

Hi, I am using Vaadin 8 to develop my new application.

It has two modes, Create & View. On clicking on view a table(Grid in Vaadin 8) is expected.

grid.addColumn(Person::getName).setCaption(“Name”);
grid.addColumn(Person::getBirthYear).setCaption(“Year of birth”);

The above is code i found in vaadin framework docs which is using method reference.

I am invoking the view from a common point and the pages view part will fire a HQL and a result will be provided to the grid. And i am using custom annotation to mark the Table Colums.

On the basis of that i will be having a map with key as Variable/ Field names and value as properties like header, hideHeader etc.

My doubt is will i be able to dynamically iterate the array and build the getName if the variable name is name which is required to be passed to the Method Interface.

Thanks in advance

It is rather difficult (to my mind at least) to follow what is being asked here. It would be really helpful if you could share a more complete code-example and ask the question on its basis.

Tarek Oraby:
It is rather difficult (to my mind at least) to follow what is being asked here. It would be really helpful if you could share a more complete code-example and ask the question on its basis.

Thanks Tarek, Had been lil busy with office work. didnt get time to check here. i will post the code.

The following is the sample of a hibernate model

@Id
@GeneratedValue
@ViewTableColumn(headerName = "id", hideHeader = true)
@Column(name = "id")
private long id;

@ViewTableColumn
@Column(name = "name", length = 500, nullable = false)
private String name;

@ViewTableColumn
@Column(name = "code", length = 50, nullable = false)
private String code;

The Following is my custom Annotation

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ViewTableColumn {

	public String headerName() default "";

	public boolean hideHeader() default false;

}

I am iterating the result of my view page and gonna enrich the following map with key as the fieldVariable name for eg: id, name, code and value as

Map<String, Map<String, Object>> fieldPropertiesMap = new LinkedHashMap<String, Map<String, Object>>();

My Doubt is whether the highlighted portion can be made dynamic based on the key of map like

if key is id then getId
if key is name then getName
if key is code then getCode

if (CommonLibrary.isNotEmpty(fieldPropertiesMap)) {
	for (Map.Entry<String, Map<String, Object>> field : fieldPropertiesMap.entrySet()) {
		if (!CommonLibrary.toBoolean(field.getValue().get(TBL_HIDE_HEADER))) {
			**grid.addColumn(OfficeModel::getName).setCaption(field.getValue().get(TBL_HEADER_NAME).toString());**
		}
	}
}

i am planning to write a generic approach for this view table population OfficeModel will be dynamically passed from a screens UI page. this can facilitate the clicking of view link on menu can display all saved data in a grid.