vaadin / vaadin/framework

Grid Editor opens crashes for new items in multi-select

Open
#7,906 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Stale v7
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Originally by fgrazi


The problem occurs when client code adds an item to the container and immediately edits it but only if the grid is in multi-select mode (took some time to understand bug conditions). To reproduce simply try the class below:


package com.fga-software.mypackage.views;

import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.VerticalLayout;

public class TestView extends VerticalLayout implements View {

  public static final String VIEW_NAME = "test";

  private final BeanItemContainer<Person> container;
  private final Grid grid;

  public TestView() {
    setSpacing(true);
    setMargin(true);
    addComponent(new InsertButton());
    container = new BeanItemContainer<>(Person.class);
    grid = new Grid(container);

    //NOTE if you change to single selection mode works fine
    grid.setSelectionMode(Grid.SelectionMode.MULTI);
    grid.setFrozenColumnCount(1);
    addComponent(grid);
    grid.setSizeFull();
    grid.setEditorEnabled(true);
  }

  @Override
  public void enter(ViewChangeListener.ViewChangeEvent event) {
  }

  private class InsertButton extends Button {

    public InsertButton() {
      super("Add a person");
      addClickListener((ClickEvent event) -> {
        Person p = new Person();
        container.addBean(p);
        grid.editItem(p);
      });
    }

  }

  public static class Person {

    String FirstName # "Richard", lastName"Nixon";

    public String getFirstName() {
      return FirstName;
    }

    public void setFirstName(String FirstName) {
      this.FirstName = FirstName;
    }

    public String getLastName() {
      return lastName;
    }

    public void setLastName(String lastName) {
      this.lastName = lastName;
    }

  }

}

then change selection mode to single and everything works fine.


Imported from https://dev.vaadin.com/ issue #20452

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied TestView reproduction with Grid in multi-selection mode, then compare it with single-selection behavior. Trace the interaction between BeanItemContainer.addBean and grid.editItem, and verify the fix with a regression test covering a newly added item opened for editing in multi-select mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.