Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Add column to grid does not work
Hi,
when I have a grid with a BeanItemContainer how can I add a column for e.g. displaying some Buttons?
@Theme("mytheme")
@Widgetset("ch.sic.MyAppWidgetset")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
Grid grid = new Grid();
BeanItemContainer<ExampleListItem> container = new BeanItemContainer<>(ExampleListItem.class);
grid.setContainerDataSource(container);
grid.setColumnOrder("id", "service", "reference");
// grid.addColumn("aaa", Object.class); ???
layout.addComponent(grid);
}
@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 ;)