How to respond to click on a table row in vaadin

Johan picture Johan · Feb 3, 2013 · Viewed 20.6k times · Source

I've got the following code:

public Button getBtnSubmit(com.vaadin.ui.Button.ClickListener l) {
    if (null != l) {
        btnSubmit.addListener(l);
    }
    return btnSubmit;
}

public Table getTableCompany(HeaderClickListener hl) {
    if (null != hl) {
        tableCompany.addListener(hl);
    }
    return tableCompany;
}

I would like to add a listener that fires when I select a (different) row in the table.
This so that I can refresh some other controls with the table data, which listener should I use?

Answer

Ishan Thilina Somasiri picture Ishan Thilina Somasiri · Nov 21, 2013

addListener is deprecated now. Use the following instead.

table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
    @Override
    public void itemClick(ItemClickEvent itemClickEvent) {
        System.out.println(itemClickEvent.getItemId().toString());
    }
});