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.
Access to item in grid converter
Hi, I have a converter for a column that need data of others columns of item for know how do convert value.
How do I get item inside a grid converter?
According to my understanding there is no way to do that in a Converter, since it doesn't know anything about the Grid. If you need to do something like you describe, you need to do that in a Renderer, since in the RendererConnector you get access to RendererCellReference (it is passed as parameter to render method). Via that object you get access to Grid and can inspect other values in the row.
Thanks.
Finally, I hack the class "RpcDataProviderExtension":
private JsonValue getRowData(Collection<Column> columns, Object itemId) {
try {
Item item = container.getItem(itemId);
// ENACCION - CSZ - permite obtener el item
VaadinSession.getCurrent().setAttribute("GridRowData["+Thread.currentThread().getId()+"]", item);
JsonObject rowData = Json.createObject();
Grid grid = getGrid();
for (Column column : columns) {
Object propertyId = column.getPropertyId();
Object propertyValue = item.getItemProperty(propertyId).getValue();
JsonValue encodedValue = encodeValue(propertyValue,
column.getRenderer(), column.getConverter(),
grid.getLocale());
rowData.put(columnKeys.key(propertyId), encodedValue);
}
final JsonObject rowObject = Json.createObject();
rowObject.put(GridState.JSONKEY_DATA, rowData);
rowObject.put(GridState.JSONKEY_ROWKEY, keyMapper.getKey(itemId));
if (visibleDetails.contains(itemId)) {
// Double check to be sure details component exists.
detailComponentManager.createDetails(itemId);
Component detailsComponent = detailComponentManager.visibleDetailsComponents
.get(itemId);
rowObject.put(
GridState.JSONKEY_DETAILS_VISIBLE,
(detailsComponent != null ? detailsComponent
.getConnectorId() : ""));
}
rowReference.set(itemId);
CellStyleGenerator cellStyleGenerator = grid.getCellStyleGenerator();
if (cellStyleGenerator != null) {
setGeneratedCellStyles(cellStyleGenerator, rowObject, columns);
}
RowStyleGenerator rowStyleGenerator = grid.getRowStyleGenerator();
if (rowStyleGenerator != null) {
setGeneratedRowStyles(rowStyleGenerator, rowObject);
}
return rowObject;
} finally {
VaadinSession.getCurrent().setAttribute("GridRowData["+Thread.currentThread().getId()+"]", null);
}
}
And now I can get Row Reference in this way on Renderer:
@Override
public JsonValue encode(String value) {
BackedItem item = (BackedItem) (VaadinSession.getCurrent().getAttribute("GridRowData["+Thread.currentThread().getId()+"]"));
SelectRender.this.fieldHelper.setCurrentRow((Row) item.getObject());
String decodeValue = SelectRender.this.fieldHelper.getDecodedValue(value);
//System.out.println("SelectRender item["+item+"] value["+value+"] decodeValue["+decodeValue+"]");
return super.encode(decodeValue);
}
This has the disadvantage of having to be very careful with the Update of Vaadin.