Using the multi-select function with a custom action

Hey,

I was wondering if it is possible to use the multi-select function on rows for custom made actions. I created a button that users press, and it sets the date of a row to today. But I would like to make it so that users can select multiple rows, and press the button once instead of having to press it multiple times.

Right now I am using the code from one of the demo’s, but this only works for one row. Any suggestions which functions to use to get this to work for multiple rows?

package com.company.machineonderhoud.web.auto;

import com.company.machineonderhoud.entity.Auto;
import com.haulmont.cuba.gui.components.AbstractLookup;
import com.haulmont.cuba.core.global.DataManager;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.data.Datasource;
import java.util.Date;
import javax.inject.Inject;

public class AutoBrowse extends AbstractLookup {

    @Inject
    public Datasource<Auto> autosDs;

    @Inject
    public DataManager dataManager;

    public void onAfronden(Component source) {
        Auto selectedAuto = autosDs.getItem();
        if (selectedAuto == null) {
            showNotification("Selecteer een onderhoudsregel!");
            return;
        }

        Date date = new Date();
        selectedAuto.setLaatstOnderhoud(date);

        dataManager.commit(selectedAuto);
        autosDs.refresh();

        showNotification("Klaar!", NotificationType.TRAY);
    }


}

Thanks in advance!

Hi,

You have to use the table instance for that.

autosTable.getSelected() will give you all selected items (you have to configure multiselect=true in the xml descriptor).

Bye
Mario

1 Like

Hey Mario,

It works perfectly. Thanks a lot!