For example, if Person has a reference to an Address object, which has a property postalCode, you can add a column for the postal code with:
grid.addColumn("address.postalCode");
The column’s key will be "address.postalCode" and it’s header will be "Postal Code".
But when I try similar process, I am getting the below error. What did I miss ?
Caused by: java.lang.UnsupportedOperationException: This method can't be used for a Grid that isn't constructed from a bean type
at com.vaadin.flow.component.grid.Grid.addColumn(Grid.java:1083)
Like the error message says, if you’re not using the Grid<>(YourBean.class) constructor (which scans your bean class for properties and automatically adds columns), you can’t use the addColumn overload that takes a String input parameter.
You can either switch to that method (if you’re ok with the Columns coming from your bean class’s properties) or use another overload of the addColumn method. For example, one with a Lambda expression, like grid.addColumn(address -> address.getPostalCode());