有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java更新gwt CellList中的映像

我正在使用Blob在Google应用程序引擎中存储图像。当我使用ListDataProvider的add()方法在CellList中添加新数据时,它会变得非常完美

以下是AbstractCell的扩展版本:

@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
        AppsBean value, SafeHtmlBuilder sb) {
    String url=GWT.getModuleBaseURL()+"fetchIcon?appId="+value.getId()+"&requestType=icon";
    sb.appendHtmlConstant("<Table>");
    sb.appendHtmlConstant("<tr><td rowspan='3'>");
    sb.appendHtmlConstant("<img src='"+url+"' style='width : 75px ;height: 75px;' />");
    sb.appendHtmlConstant("</td><td>");
    sb.appendEscaped(value.getAppName());
    sb.appendHtmlConstant("</td></tr><tr><td>");
    sb.appendEscaped(value.getAppLink());
    sb.appendHtmlConstant("</td></tr><tr><td>");
    sb.appendEscaped(value.getAppDesc());
    sb.appendHtmlConstant("</td></tr>");
    sb.appendHtmlConstant("</Table>");
}

Servlet代码:

        String appId = get(request, "appId");
    String requestType = get(request, "requestType");
    log.info("Your request for apps icon: " + appId + ", requestType: " + requestType);
    if (requestType.equalsIgnoreCase("icon")) {
        Apps icon = appsServiceImpl.getApp(Long.valueOf(appId));
        log.info("We got apps for you: " + icon);
        if(icon != null){
            log.info("We got store logo for you: " + icon.getIcon());
            response.getOutputStream().write(icon.getIcon());
        }
    }

现在,当我更新Blob中的图像时,我希望同样的图像反映在CellList的单元格中。对于单元格的更新,我使用ListDataProvider的set()方法

使用set()方法,单元格中的文本数据得到完美更新,但图像没有得到更新。url也得到了完美的生成,但是一旦单元格被呈现,就不会再次生成对Servlet的调用

有人知道我应该怎么做才能再次生成对Servlet的调用吗


共 (1) 个答案

  1. # 1 楼答案

    在url的末尾添加参数。类似于随机整数的东西。 不会刷新图像,因为浏览器假定图像与以前相同,并使用缓存中的图像

    Random random = new Random();
    String url=GWT.getModuleBaseURL()+"fetchIcon?appId="+value.getId()+"&requestType=icon" + "&r=" + random.nextInt();