Adding Column to a Grid for a property in the referenced object.

From the documentation,

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());

-Olli

Thanks, that worked.

I think the documentation should be little bit more clear.

Sure. Can you give a link to the docs page where that part you quoted is?

-Olli

Here is the link.

https://vaadin.com/docs/v10/flow/components/tutorial-flow-grid.html

Thanks. There’s a clarifying pull request to the documentation here: https://github.com/vaadin/flow-and-components-documentation/pull/209 - note that it’s a public repository, so changes can be suggested there too.