Get component from table's generated cell

Hi All,

I am generating table cell with components like label and button. Is there way to get these components using table row reference.?

Thanks in advance.


I don’t think there is any easy way to do that. Can you store references to your components somewhere?

Hi Sara ,

Yes .Right now i have implemented my logic by saving component references .
I am using lazyquery container for the table .And table data is expected to be huge :frowning:
So,I was looking for a better approach.

Why do you need to get the components, it is not enough f.e. to get the selected value only?

Something like this?

        // itemId is used as the identifier in the Table and Container.
        final Object itemId = new Object();
        // The Field to be stored in the Table and Container.
        final TextField originalField = new TextField("Text Field");
        // The Container to bind the Table against.
        final IndexedContainer ic = new IndexedContainer();
        // The Table to hold the TextField and Label.
        final Table table = new Table("Table", ic);
        // Set up the properties of the IndexedContainer.
        // A TextField and a Label.
        ic.addContainerProperty("label", Label.class, new Label());
        ic.addContainerProperty("field", TextField.class, new TextField());
        // Create a new IndexedContainer item.
        final Item item = ic.addItem(itemId);
        // Set the Item's values.
        item.getItemProperty("label").setValue(new Label("Test Label"));        

        // Get the Field from the IndexedContainer Item;
        final TextField field = (TextField)item.getItemProperty("field").getValue();
        // Get the Item back out of the Table.
        Item itemFromTable = table.getItem(itemId);
        // Get the Field from the Item the from Table.
        TextField fieldFromTable = (TextField)itemFromTable.getItemProperty("field").getValue();
        // Verify the TextField from the Table Item is the original TextField.
        System.out.println("TextField correct: " + originalField.equals(fieldFromTable));


Code you have mentioned works fine.
But i have a generated column with Label component . I am not able to access the component using getItemProperty as you have mentioned .Is there any other way ?

Below is the code sniplet:

  table.addGeneratedColumn( "newColumn", new ColumnGenerator()
     private static final long serialVersionUID = 31113154571093783L;

     public Object generateCell( final Table source, final Object itemId, final Object columnId )
        final Label label = new Label( "<b>" + "name " + "</b><br/>" + "description", ContentMode.HTML );
        return label;
  } );

System.out.println(“new value:::”+item.getItemProperty(“newColumn”).getValue()) is printing “null”

My requirement is to update the label of this generated column on certain event.