How to get cell components in a table

In the
book example
, I did some modifications:

final TreeTable ttable = new TreeTable("My TreeTable");
ttable.addContainerProperty("Name", CheckBox.class, "");
ttable.addContainerProperty("City", CheckBox.class, "");
ttable.setWidth("20em");
// Create the tree 
nodesttable.addItem(new Object[]{new CheckBox("Root"), new CheckBox("Helsinki")}, 0);

Is it possible to get CheckBox City if a ClickListener is added in CheckBox Name? in other words, Can I get the cell component if I know the number/name of row and column?

In non-editable mode, when you have components in a table, they are just property values. You should be able to get the component with “table.getItem(itemId).getItemProperty(propertyId).getValue()” or “table.getContainerProperty(itemId, propertyId).getValue()”. They return an Object, which you need to cast to the proper component type.

It looks like that “table.getItem(itemId).getItemProperty(propertyId).getValue()” or “table.getContainerProperty(itemId, propertyId).getValue()” could not get the cell component:

  1. table.getItem(itemId).getItemProperty(propertyId) returns class Property, it cannot cast to component type.
  2. table.getItem(itemId).getItemProperty(propertyId).getValue() returns class type of propertyId in itemId, e.g. String, not component type.

Checked with the source code of Table, there are private methods Table.getVisibleCellsUpdateCacheRows() / getVisibleCellsNoCache(), which contain cell components information. The problem is they are all private methods and cannot be accessed directly.

  1. Yes, it returns a Property object.
  2. As your property type is a CheckBox, the property.getValue() returns a CheckBox.

See
this example
.

The visible cells cache in table is only relevant in the editable mode, when the visible components are generated dynamically with the table field factory. In your case, the table is in the non-editable mode, which is good if you want to have it easy - all the components in the table exist all the time. Interacting in the editable mode is much more difficult and easily causes memory leaks.

How to achive it with Table with BeanItemContainer as data source? As
Property
I get
MethodProperty
and as
value
, the string used in setter.

This thread is about a special case where you have components in a non-editable table. In this case, the property type is a component type, such as a CheckBox, not Boolean.

In your case, the property type is apparently String, and you want to have editing for the string value. In that case, you probably should put the table in editable mode, as
described in the book
.