当我动态生成条形码时,它总是打印以前的输入,而不是最新的代码。当我使用浏览器上的刷新按钮刷新页面时,会显示正确的条形码。但是如果我使用 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 Controller 。
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;
}
}
引用文献:
最佳答案
在p:graphicImage
上设置cache="false"
。
关于jsf - 尝试显示动态生成的条形码时显示上一个条形码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25226733/