Search code examples
javavaadinvaadin8vaadin-grid

Thumbnails not rendering correctly in Vaadin Grid in Chrome


I'm using the latest version 8.1.4 of Vaadin. The code is simple consists of three columns where one column is an Image component. When that row is selected the Image component changes the image to another row's image for the grid. Eventually after a number of select and unselect (the image also changes on unselect) the image eventually settles on an image.

public StreamResource getImageForGrid()
{
    StreamResource streamResource = new StreamResource(
        () -> {
            System.out.print("Line is not output sometimes when rendering grid");
            return new ByteArrayInputStream(getConvertedThumbnailImage());
        }, name + ".jpg");
    streamResource.setCacheTime(0);
    return streamResource;
}

For whatever reason the System.out.println line will not be executed in Chrome consistently. In Firefox it's always called when rendering the grid but in Chrome the System.out.println is often not called which results in the above weird error and behavior. Sometimes it's not even called at all which makes me confused as to how the thumbnails in the grid are even generated? I have to assume some kind of browser caching?

My grid consists of:

grid.addComponentColumn(
    gridData -> new Image(gridData.getName(), gridData.getImageForGrid());

Has anyone run into this bug? And if so how do you resolve it?

PS: The only reason I'm using Image components is that there is no other way to present server generate thumbnails in a grid other than this way that I can see...


Solution

  • I was able to resolve the issue using the following add-on: https://vaadin.com/directory#!addon/grid-renderers-collection-for-vaadin7

    The code is simply:

    grid.addColumn(data.getThumbnailByteArray(), BlobImageRenderer());