How to get the Item value of an child item from TreeTable.

I need the value from list which is the child element in TreeTable.

Here is my code:--------------------
//Code for addContainerProperty
TreeTable table = new TreeTable(“TreeTable”) ;
final HierarchicalContainer container = new HierarchicalContainer();
container.addContainerProperty(“billOfladingNo”, String.class, “”);

    //Code to display the TreeTable in the View
            new Object {"containerNo"});
            new String {"Container No."});

(Here we are using the addGeneratedColumn to apply the Color based on Container number we are getting
for Table component, the code is working good but for TreeTable it is not working)
table.addGeneratedColumn(“containerNo”, new Table.ColumnGenerator() {
public Component generateCell(final Table source, final Object itemId, final Object columnId) {


//Trail 1
String containerNo = item.getItemProperty(“containerNo”).getValue().toString(); //This Line Throughs NullPointerException since item is null.


final HierarchicalContainer container = new HierarchicalContainer();
Item item1 = (Item) container.getParent(itemId);
container.getContainerProperty(itemId,“containerNo”);//It returns an interger value


Container dataSource = source.getContainerDataSource();
if (dataSource instanceof Container.Hierarchical) {
Container.Hierarchical h1 = (Container.Hierarchical) dataSource;
System.out.println(“child::::::” + h1.getChildren(1)); //This continously displays the first record value , but does not display the remaining records

              return new Label();

Above are my 3 Trials but none of them works.
I need the value from list which is the child element in TreeTable.



So i need Child1 ,Child2 and Child3 to apply some logic but it always displays Child1.

(Can we get the same behaviour of addGeneratedColumn of Table into TreeTable)

Any Help is appreciated :slight_smile:

Sorry it’s a bit unclear to me what do you need. Can you describe what properties do you have in the hierarchical container and what is the generated property what do you need to generate.

Below i have attached the screenshot,

For Every Parent record i want to get the Child object using addGeneratedColumn.

In Table Component:

table.addGeneratedColumn(“containerNo”, new Table.ColumnGenerator() {
public Object generateCell(Table source, Object itemId, Object columnId) {
Item item = source.getItem(itemId);
String containerNo = item.getItemProperty(“containerNo”).getValue().toString();

// From the above line will get the value but in TreeTable Component we gettting ClassCastException because it’s returing the Integer not the Object


What is the type of containerNo property when you add it to the HierarchicalContainer?

It’s String Type,

container.addContainerProperty(“containerNo”, String.class, “”);

Does something like this work:

        BeanItemContainer<MyPojo> items = new BeanItemContainer<>(MyPojo.class);
        ContainerHierarchicalWrapper container = new ContainerHierarchicalWrapper(items);

        container.setParent(myPojo2, myPojo);

        TreeTable tree = new TreeTable("", container);
        tree.addGeneratedColumn("containerNo", new ColumnGenerator() {

            public Object generateCell(Table source, Object itemId, Object columnId) {
                String containerNO = (String) source.getItem(itemId).getItemProperty("containerNo").getValue();

Thank you for immediate response for all.

Even we got the solution by the folloing code:

Property prop = source.getItem(itemId).getItemProperty(“containerNo”);
if (prop != null && prop.getValue() != null) {
String containerNo = prop.getValue().toString();

But i have one more doubt,

ie By using TreeTable i am trying to display the ToolTips but it is not working, getting ClassCastException (java.lang.Integer cannot be cast to

table.setItemDescriptionGenerator(new AbstractSelect.ItemDescriptionGenerator() {
public String generateDescription(Component component, Object itemId, Object propertyId) {
//Here propertyId is the columnName, itemId is the integer values of parent/child id’s.

String tooltip = “”;

//getting ClassCastException (java.lang.Integer cannot be cast to for below line
HouseBillVO vo = (HouseBillVO) itemId;

if (propertyId != null && propertyId.toString().equalsIgnoreCase(STATUS)) {
tooltip = vo.getStatusToolTip();
if (propertyId != null && propertyId.toString().equalsIgnoreCase(START)) {
tooltip = vo.getStartTimeToolTip();
return tooltip;

Using ItemId we can get the required information for Table Component but for TreeTable Component it is not working.
Any solutions ?

What are the container types you are using with Table? BeanItemContainer perhaps? Are you using HierarchicalContainer for TreeTable? HierarchicalContainer item ids are integers. You can wrap BeanItemContainer with ContainerHierarchicalWrapper which allows you to have the same itemId behavior as in BeanItemContainer (id is the pojo itself).