【问题标题】:Previous barcode is displayed when attempting to display dynamically generated barcodes尝试显示动态生成的条形码时会显示以前的条形码
【发布时间】:2014-10-03 07:19:06
【问题描述】:

当我动态生成条形码时,它总是打印以前的输入,而不是最新的代码。当我在浏览器上使用刷新按钮刷新页面时,会显示正确的条形码。但是如果我用 JSF 命令按钮刷新页面,仍然是以前的结果。我哪里出错了?

JSF 2.1 Primefaces 4.0 烧烤 1.5 测试版 Chrome/Firefox 最新更新

<p:graphicImage value="#{barcodeController.createBarcodeByCode(patientController.current.code)}" 
                style="max-width: 7.5cm; padding: 10px; margin: 10px;" >
</p:graphicImage>

这是来自具有请求范围的 JSF 控制器。

public StreamedContent createBarcodeByCode(String code) {
    FacesContext context = FacesContext.getCurrentInstance();
    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        // So, we're rendering the view. Return a stub StreamedContent so that it will generate right URL.
        return new DefaultStreamedContent();
    } else {
        barcode = null;
        System.out.println("code = " + code);
        if (code == null || code.trim().equals("")) {
            return null;
        }
        File barcodeFile = new File(code);
        try {
            BarcodeImageHandler.saveJPEG(BarcodeFactory.createCode128C(code), barcodeFile);
            barcode = new DefaultStreamedContent(new FileInputStream(barcodeFile), "image/jpeg");
        } catch (Exception ex) {
            System.out.println("ex = " + ex.getMessage());
        }

        return barcode;
    }
}

参考资料:

1. Dynamic StreamContent Answer by BalusC

2. Dynamic Barcode with Primefaces

【问题讨论】:

    标签: jsf primefaces barbecue


    【解决方案1】:

    在图形图像上设置cache=false

    【讨论】:

      猜你喜欢
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      相关资源
      最近更新 更多