How to respond to click on a table row in vaadin

北城余情 提交于 2019-12-05 03:47:33

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());
    }
});

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.

You want to add a ValueChangeListener

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.

Read https://vaadin.com/book/-/page/components.table.html, section 5.15.1 "Selecting Items in a Table". You want to add a Property.ValueChangeListener.

Many of these answers are both correct, and incorrect.

If you need to get the selected items in response to the click, register a ValueChangeListener. Calling getValue() to retrieve the selection from the ItemClickListener might be 1 item behind in a MultiSelect list. For example, the set of items won't include/exclude the item triggering the callback. You will not have a reference to the clicked item however.

If you simply want to respond to a click on an item, and do not need to consider the current selection state, register an ItemClickListener instead. This way you will know what item was actually clicked.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!