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”:

[font=courier new]
[size=2]
private JsonValue getRowData(Collection columns, Object itemId) {
try {
Item item = container.getItem(itemId);

        [color=#FF0000]

// ENACCION - CSZ - permite obtener el item
VaadinSession.getCurrent().setAttribute(“GridRowData[”+Thread.currentThread().getId()+"]
", item);

[/color]
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);
}
}
[/size]
[/font]

And now I can get Row Reference in this way on Renderer:

[size=2]
[font=courier new]
@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);
        }

[/font]
[/size]



This has the disadvantage of having to be very careful with the Update of Vaadin.