【问题标题】:Thumbnails not rendering correctly in Vaadin Grid in Chrome缩略图无法在 Chrome 的 Vaadin Grid 中正确呈现
【发布时间】:2018-02-27 16:48:45
【问题描述】:

我正在使用最新版本的 Vaadin 8.1.4。代码很简单,由三列组成,其中一列是图像组件。 When that row is selected the Image component changes the image to another row's image for the grid.最终经过多次选择和取消选择(取消选择时图像也会发生变化),图像最终会固定在图像上。

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;
}

无论出于何种原因,System.out.println 行将不会在 Chrome 中始终如一地执行。在 Firefox 中,它总是在渲染网格时被调用,但在 Chrome 中,System.out.println 通常不会被调用,这会导致上述奇怪的错误和行为。有时甚至根本没有调用它,这让我对网格中的缩略图是如何生成的感到困惑?我必须假设某种浏览器缓存?

我的网格包括:

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

有人遇到过这个错误吗?如果是这样,您如何解决?

PS:我使用图像组件的唯一原因是,除了我可以看到的这种方式之外,没有其他方法可以在网格中呈现服务器生成缩略图...

【问题讨论】:

  • 我也认为这是浏览器图像缓存问题。仅用于测试:当您将Image 包装在布局中并在选择/取消选择时用新的图像组件替换图像组件时会发生什么? (我假设你目前使用的是setSource
  • 是的,我正在使用 setSource。它在 Firefox 中完美运行,但在 Chrome 中却不行。另外,我不会在选择/取消选择时更改图像,那里根本没有调用任何代码。

标签: java vaadin vaadin8 vaadin-grid


【解决方案1】:

我能够使用以下插件解决问题:https://vaadin.com/directory#!addon/grid-renderers-collection-for-vaadin7

代码很简单:

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

【讨论】:

    猜你喜欢
    • 2019-05-28
    • 2012-05-22
    • 2020-01-10
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多