Skip to content

Clicking on button components inside grid may cause IndexOutOfBoundsException if button changes grid items in multi selection mode #62

@randomuser1231232

Description

@randomuser1231232

Description of the bug

While multiselection mode is active clicking on a button inside the grid selects the underlying item. When the button itself changes the items displayed in the grid, a IndexOutOfBoundsException is thrown when the index of the selected item is smaller than the new item size.

This does not happen in single select mode. In standard grid this does not happen at all.

Expected behavior

Clicking on button inside a grid does:

  • Not select item (as in single selection mode, but still close non-modal dialogs/popups)
  • Not cause any errors

How to reproduce

  • Click on delete button of last item in grid
@Route
public class MainView extends VerticalLayout {
    public MainView() {
        this.add(new TestSelectionGrid());
    }
}

public class TestSelectionGrid extends SelectionGrid<UUID> {

    private List<UUID> items;

    public TestSelectionGrid() {
        items = IntStream.range(0, 5).mapToObj(i -> UUID.randomUUID()).collect(Collectors.toList());

        this.setWidth(600, Unit.PIXELS);
        this.setHeight(800, Unit.PIXELS);

        addColumn(LitRenderer.<UUID>of("""
                <vaadin-button theme="icon" @click="${handleClick}">
                    Delete
                </vaadin-button>
                """).withFunction("handleClick", item -> {
                    items.remove(item);
                    getDataProvider().refreshAll();
                }
        )).setAutoWidth(true).setFlexGrow(0).setResizable(false).setSortable(false).setFrozen(true);
        addColumn(id -> id);

        setDataProvider(new AbstractBackEndDataProvider<>() {
            @Override
            protected Stream<UUID> fetchFromBackEnd(Query<UUID, Object> query) {
                query.getLimit();
                query.getOffset();
                return items.stream();
            }

            @Override
            protected int sizeInBackEnd(Query<UUID, Object> query) {
                return items.size();
            }
        });

        this.setSelectionMode(SelectionMode.MULTI);
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions