簡體   English   中英

嘗試顯示動態生成的條形碼時會顯示以前的條形碼

[英]Previous barcode is displayed when attempting to display dynamically generated barcodes

當我動態生成條形碼時,它總是打印以前的輸入,而不是最新的代碼。 當我在瀏覽器上使用刷新按鈕刷新頁面時,會顯示正確的條形碼。 但是如果我用 JSF 命令按鈕刷新頁面,仍然是以前的結果。 我哪里出錯了?

JSF 2.1 Primefaces 4.0 燒烤 1.5 beta Chrome/Firefox 最新更新

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

這是來自 JSF controller 請求 scope。

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. BalusC 的 Dynamic StreamContent Answer

2.動態條碼Primefaces

在graphicImage上設置cache=false

(typo " ") cache="false" (我不能評論,抱歉)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM