Add nested objects properties in Vaadin 8 container

Since there is no BeanItemContainer now with the grid how is it possible to bind nested objects properties to the Grid, like:

class Person { Address address; } class Address { String street } I would like to bind Person::getAddress::getStreet

why cannot we just say:


Playing around with it I was able to acheive it this way:

grid.addColumn(person -> person.getAddress().getStreet()).setCaption("Address Street");

But now I get unwanted columns displayed for person how to selectively show columns?

I am under the impression that nested property binding is not supported (yet)

I solved it by setting unique column ids to the nested columns and using the following:

grid.addColumn(person -> person.getAddress().getStreet()).setCaption("Address Street").setId("streetAddress");
grid.setColumns("name","age", "streetAddress");

Probably because Java doesn’t support it(?) :wink:

But yes, it would be nice to have some native way of doing it instead of various workarounds like you outlined (or adding “flattening” getters in the root object etc)

Hi all!
Ii think I have similar issues to Kareem.
I have the following class files

class Country {
String name;

class City {
String name;
Country country;

class Person {
City bornAt;

I also have a Grid where I need to display the name of the Country and the name of the City where she was born

Grid<Person> grid = new Grid<>(Person.class);

Both nested properties end up to “name”, so I finally get the excpetion
IllegalArgumentException(“Duplicate ID for columns”)
I might be all wrong, but the method

public Column<T, ?> addColumn(String propertyName, AbstractRenderer<? super T, ?> renderer){...} in Grid class seems to be having some issues, since it checks for column existance using the propertyName, but it finally sets the new column id using the definition.getName().

Is it some known bug? Should we only be using the addColumn(ValueProvider<T, V> valueProvider) method for adding columns to Grid?
Thanks everyone in advance.

Is there a way to add nested beans in the grid like we used to do with big.addNestedProperty …? the person->person.getCity ().getName () return a null pointer exception when the person is not given a city. Moreover this approach fails while building.

Hi Adil,

I have the same problem. Did you find a solution?

Hi Rodrigo, Unfortunately no… I just postponed the migration to vaadin 8 till mid 2018. I am using vaadin 7. I think there are still many issues with grid v8 that were easier with table v7.

I found a solution on
Crud UI Add-on

getGrid().setColumns("name", "mainGroup", "active");
getGrid().getColumn("mainGroup").setRenderer(group -> group == null ? "" : ((Group) group).getName(), new TextRenderer());

I did not test performance but it works.