Check if rows selected in table


I am a beginner, so sorry for silly questions.
I have read the documentation, but for me there aren’t enough example and not really clear.

In my project the user can select more rows in Customers browse screen. And after it user should click my EditStatusBtn. First I want to check if any row has selected, but it isn’t run with that code:

public class CustomerBrowse extends AbstractLookup {
    protected Table<Customer> table;

    public void onEditStatusBtn(Component source) {
        if (table.getSelected().isEmpty()) {
            showNotification("Select detail rows first", NotificationType.HUMANIZED);

Can you help me, what I’ve missed?


I tried too, i need it too, but I get a NullPointerExeption if nothing selected. Am I missed somtehing?
ok i got it, no question.

I think that better option for you is to use ItemTrackingAction.
First of all you should add an action and a button into your Table component in screen descriptor:

<table id="customersTable"
        <action id="editStatus"
    <buttonsPanel id="buttonsPanel"
        <button id="editStatusButton"

Let’s have a look an attributes of action and button.

trackSelection=“true” disables a button linked to this action if any row is not selected.

invoke=“editStatus” means that after clicking the button method with name editStatus will be executed.

action=“customersTable.editStatus” links button and action. It means that clicking the button leads to the action perform.

Here is example of screen controller with code which will be executed after clicking the button:

private Table<Customer> customersTable;

public void editStatus() {
    Customer customer = customersTable.getSingleSelected();

    // there is no need in checking that customer is not null if you use ItemTrackingAction
    String message = String.format("Customer %s %s was selected", customer.getFirstName(), customer.getLastName());

You can find additional information here

Thank you for your answer. It works fine :slight_smile:
But what if the user selected more rows than one?

Szabó Eszter, the simpliest variant is to invoke your method “editStatus” and check if there are selected rows in your table, ItemTrackingAction supports only single selection mode.

Is trackSelection deprecated ???

Hello @akhil

No, it is not. Please create a new topic if you’ve encountered a problem