Problem with grid

I create one Grid and one BeanItemContainer just like this:

private BeanItemContainer<TabelaCusta> tabelaCustaContainer;
private List<TabelaCusta> tabelaCustas = new ArrayList<TabelaCusta>();

so in my button i put this code:

tabelaCustaContainer = new BeanItemContainer<TabelaCusta>(TabelaCusta.class, tabelaCustas);
tabelaGrid.setContainerDataSource(tabelaCustaContainer);
tabelaCustas.addAll(TabelaCusta.mock());

so in my 1 click the grid only create the columns, but if I click again the grid show the data.

So i try to move the code(I try only the 1 line, and the 2 lines, ) to enter and try in constructor too

tabelaCustaContainer = new BeanItemContainer<TabelaCusta>(TabelaCusta.class, tabelaCustas);
tabelaGrid.setContainerDataSource(tabelaCustaContainer);

but don`t work. only works if I run 2 time (or more) the hole code.

anyone know why??

tks

I’m using the vaadin 7.6.6

tks

Just a guess, try appending ?debug and ensure theme, server and client version match in the ‘info’? tab of the Vaadin client debugger. And/Or debug the thing and ensure your collection tabelaCustas actually has elements from your mock() method.

This is the info:

Client engine version7.6.6
Server engine version7.6.6
Theme version7.6.6
Push server version2.2.7.vaadin1
Push client version2.2.13.vaadin3-jquery (note: does not need to match server version)
Widget setbr.com.lumera.CaixaWidgetset
Themecaixa
Communication methodClient to server: XHR, server to client: long-polling
Heartbeat300s

And this is my mock method:

public static List<TabelaCusta> mock(){

        List<TabelaCusta> retorno = new ArrayList<>();
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));
        retorno.add(new TabelaCusta(1, new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), new BigDecimal("23"), "tabelaligada", 0, 0, 123, 23, 443, 323, null, null, null, null, "1A tabela", "1A"));

        return retorno;
    }

I think the problem is you are not adding your data directly to the container. Try to invoke
addAll
on the BeanItemContainer

tabelaCustaContainer = new BeanItemContainer<TabelaCusta>(TabelaCusta.class, tabelaCustas);
tabelaGrid.setContainerDataSource(tabelaCustaContainer);
tabelaCustaContainer.addAll(TabelaCusta.mock());

Regards
Marco