Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to respond to click on a table row in vaadin

Tags:

java

vaadin

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?

like image 680
Johan Avatar asked Feb 03 '13 17:02

Johan


4 Answers

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());
    }
});
like image 153
Ishan Thilina Somasiri Avatar answered Oct 31 '22 02:10

Ishan Thilina Somasiri


I would go for ItemClickListener:

 table.addListener(new ItemClickEvent.ItemClickListener() {

            @Override
            public void itemClick(ItemClickEvent event) {
               //implement your logic here
            }
        });

edit: For Vaadin 7+, use addItemClickListener method instead of addListener.

like image 41
ogzd Avatar answered Oct 31 '22 03:10

ogzd


You want to add a ValueChangeListener

like image 1
Charles Anthony Avatar answered Oct 31 '22 02:10

Charles Anthony


If you use the ValueChangeListener don't forget to set

  table.setImmediate(true);

This means that the browser will report a change on selection immediately. If you don't set this your listener is not called.

like image 1
Bruno Eberhard Avatar answered Oct 31 '22 02:10

Bruno Eberhard