Table.addItem()

Hi all !

tableProdutos.addContainerProperty("CÓD. EXTERNO", Long.class, null);
tableProdutos.addContainerProperty("DESCRIÇÃO", String.class, null);
tableProdutos.addContainerProperty("ESTOQUE", Double.class, null);
while(rs.next()) {
              
   tableProdutos.addItem(new Object {
           Long.valueOf(rs.getString("CodExterno")), rs.getString("Descricao"), 
           rs.getDouble("Estoq")}, rs.getLong("ID_Produto"));

}

The code above works fine !
But i need an invisible property , like this :

tableProdutos.addContainerProperty("ORDEM", Long.class, null); // <-- New property INVISIBLE
tableProdutos.addContainerProperty("CÓD. EXTERNO", Long.class, null);
tableProdutos.addContainerProperty("DESCRIÇÃO", String.class, null);
tableProdutos.addContainerProperty("ESTOQUE", Double.class, null);

tableProdutos.setVisibleColumns(new Object {"CÓD. EXTERNO", "DESCRIÇÃO", "ESTOQUE"});
Long cont = 0L;
while(rs.next()) {
              
   Object itemId = tableProdutos.addItem(rs.getLong("ID_Produto"));
   Item row = tableProdutos.getItem(itemId);
   row.getItemProperty("ORDEM").setValue(++cont); // Here : NullPointerException
   row.getItemProperty("CÓD. EXTERNO").setValue(Long.valueOf(rs.getString("CodExterno")));
   row.getItemProperty("DESCRIÇÃO").setValue(rs.getString("Descricao"));
   row.getItemProperty("ESTOQUE").setValue(rs.getDouble("Estoq"));
}

Surely rs.getLong(“ID_Produto”) returns a valid value

Throws the exception : NPE

What can i do to fix this !

Thanks.

Vaadin Framework 7.4.6

Mmm, I hope you can ++ a Long object… ++ obviously works with a long, but Long are immutable… Not sure what happens there, and it might depend on Java version. I’d define the cont as a long (non-object) and increment it, and I think there would be an implicit typecast in the setValue() call.

Hi Marko !

Thanks for answer.

I change Long to long and nothing.

What happens is this :

Object itemId = tableProdutos.addItem(rs.getLong("ID_Produto")); itemId is null but

tableProdutos.addItem(new Object[] {Long.valueOf(rs.getString("CodExterno")), rs.getString("Descricao"), 
                      rs.getDouble("Estoq")}, rs.getLong("ID_Produto"));

works fine !

What can is going on ?

Ah, didn’t notice it at first, the mistake seems to be that you expect that the addItem(itemId) returns itemId, but in reality it returns the Item object.

What can i do to works ?

Marko ?

Thank you for solving the problem.

I change this :

Long cont = 0L;
while(rs.next()) {
              
   Object itemId = tableProdutos.addItem(rs.getLong("ID_Produto"));
   Item row = tableProdutos.getItem(itemId);
   row.getItemProperty("ORDEM").setValue(++cont); // Here : NullPointerException
   row.getItemProperty("CÓD. EXTERNO").setValue(Long.valueOf(rs.getString("CodExterno")));
   row.getItemProperty("DESCRIÇÃO").setValue(rs.getString("Descricao"));
   row.getItemProperty("ESTOQUE").setValue(rs.getDouble("Estoq"));
}

to this :

[code]
long cont = 0;

while(rs.next()) {

cont++;

Item itemId = tableProdutos.addItem(rs.getLong(“ID_Produto”));
itemId.getItemProperty(“ORDEM”).setValue(cont);
itemId.getItemProperty(“CÓD. EXTERNO”).setValue(Long.valueOf(rs.getString(“CodExterno”)));
itemId.getItemProperty(“DESCRIÇÃO”).setValue(rs.getString(“Descricao”));
itemId.getItemProperty(“ESTOQUE”).setValue(rs.getDouble(“Estoq”));

}

[/code]Thank you very much !

Yes, that’s how it goes. Well, the “itemId” could be rather confusing variable name there, as it’s not an ID but the actual item…

Yes, I will change it.

Thanks again Marko !