簡體   English   中英

JSF DocumentViewer 無法在 @ViewScope 中顯示 PDF

[英]JSF DocumentViewer fails to display PDF in @ViewScope

我對 JSF 比較陌生,因此需要一些幫助。
問題:我的網頁顯示 PDF。 因此我創建了一個如下的xhtml

<p:panel rendered="#{mainAppView.getMessages().isEmpty()}" styleClass="preview-panel">
    <div class="document-viewer-wrapper">
        <pe:documentViewer
            url="#{previewView.previewUrl}"
            download="Document.pdf"
            id="pdfPreview"/>
    </div>
</p:panel>

URL 由 BackingBean previewView 提供。 因此,當 jsf 嘗試顯示文檔時,它會調用 WebServlet。 WebServlet 下載文檔並顯示它,如果下載失敗,則會在 DocumentViewer 上顯示一條錯誤消息。

有沒有辦法通知 ViewScope Bean 失敗? 如果文檔下載失敗,我想禁用屏幕上的選項卡。 我讀到 servlet 無法調用 viewScope Bean。

不要將 ViewScoped 與 PDFViewer 一起使用,請改用 RequestScoped/SessionScoped/ApplicationScoped。

請參閱: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/796

BalusC 解釋了為什么 ViewScoped 也不能使用: https://stackoverflow.com/a/18994746/502366

我最終編寫了一個 JS 來實現期望的結果。 JS 監視了 pdfviewer,如果它無法加載文檔,我更新了 pdfviewer 上的消息。

暫無
暫無

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

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