How to respond to click on a table row in vaadin
20,792
Solution 1
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());
}
});
Solution 2
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
.
Solution 3
You want to add a ValueChangeListener
Solution 4
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.
Author by
Johan
http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work
Updated on July 09, 2022Comments
-
Johan almost 2 years
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? -
Patton about 11 yearsIf you wish to get the id of the row clicked on then
Integer value = (Integer) event.getItem().getItemProperty("id").getValue();
-
ogzd about 11 yearswhat about
event.getItemId()
? -
Patton about 11 yearsI believe itemId is different from id, I am speaking about a column that is hidden and whose value is used for processing at the backend.
-
Manish Patel almost 10 yearsThis is now deprecated ib Vaadin 7, the answer from Ishan Thilina Somasiri is the correct one