Table within a table

Hi,
I am creating a UI where I am placing a table. One of the column of this table contains a Table and I do specify the

parentTable.addContainerProperty( “OD”, ChildTable.class, null, “ORIGIN DESTINATION”, null, null);

ChildTable extends Table and contains 1-4 rows.

Now when I do a item id look up on parentTable, the property “OD” is always null and not returning the instance of Child table.

Can someone help me what I am doing wrong or if this is not supported by Vaadin.

Thanks
Shankar

Hi,

How have you created the ChildTables and put them to the main table?

Hi Marko,
Yes. I did add it.

when I do a item.getItemProperty(“OD”).getValue() I always get null on that property. All other properties of that item on the parent table return values.

It’s hard to see how the property values would be null if you have previously set them as non-null. Do the ChildTables show in the table? How have you created the ChildTables and put them to the main table?

There’s an example of nested tables
here
. They are maybe a bit limited use, as they usually need to have fixed height to avoid some rendering trouble.

Yes the child tables appear in the UI.

I took this example and added it to my page. and this is what I tried as below
for ( Object itemId : table.getItemIds() ) {
Property nameProperty = table.getContainerProperty( itemId, “Name”);
Property moonProperty = table.getContainerProperty( itemId, “Moons”);
Item item = table.getItem( itemId );
}

moonProperty which is the child table comes as null.

Ah, I think I know what is happening there. Fascinating.

I don’t know how you test for the null value, but you are probably testing it by somehow calling toString() for the property, not by testing “if (moonPropery == null)”.

That could occur if you are just using the debugger to inspect the values (see below).

So, it results in string “null”, because the toString() in IndexedContainerProperty in IndexedContainer (which is the default container of Table), actually returns toString() of the
value
of the property. The value of the property is the child table. A table is a property itself, and its value is the currently selected item of the child table. As there’s no item selected in the child table, it’s null. So, the toString() returns “null”.

I hope that makes it clear. :bashful:

When calling the toString() for the property, it displays some heavy warnings:

In other words, don’t do it that way.