Add column to grid does not work


when I have a grid with a BeanItemContainer how can I add a column for e.g. displaying some Buttons?

public class MyUI extends UI {

  protected void init(VaadinRequest vaadinRequest) {
    final VerticalLayout layout = new VerticalLayout();

    Grid grid = new Grid();
    BeanItemContainer<ExampleListItem> container = new BeanItemContainer<>(ExampleListItem.class);

    grid.setColumnOrder("id", "service", "reference");

//    grid.addColumn("aaa", Object.class); ???



  @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
  @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
  public static class MyUIServlet extends VaadinServlet {}


Occurured excetion is

java.lang.IllegalStateException: Container for this Grid is not a default container from Grid() constructor So, whats the correct way to add columns to a grid?

The API spec says “Note that adding a new property is only done for the default container that Grid sets up with the default constructor.”

So if you use other container type, the addColumn(…) cannot be used in the way you are attempting to do.

With BeanItemContainer you can hence add columns, which already have existing property in the container.

Oh, yeah, thanks.

GeneratedPropertyContainer wrapperContainer = new GeneratedPropertyContainer(container); did the trick :wink: