简体   繁体   中英

JSF DocumentViewer fails to display PDF in @ViewScope

I am relatively new to JSF thus need some help.
Problem: I have webpage that displays a PDF. Thus I created a xhtml as follow

<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 is provided by a BackingBean previewView. Thus when the jsf tries to display the document, it makes a call to WebServlet. The WebServlet downloads the document and displays it and if it fails to download, an error message is shown on the DocumentViewer.

Is there a way to I can notify the ViewScope Bean about the failure? I want to disable a tab on the screen if the document download fails. I read that servlet can't make call to viewScope Bean.

Do not use ViewScoped with PDFViewer use RequestScoped/SessionScoped/ApplicationScoped instead.

See: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/796

BalusC explains why ViewScoped can't be used as well: https://stackoverflow.com/a/18994746/502366

I ended up writing a JS to achieve the desire result. JS monitored the pdfviewer and if it fails to load the document, I updated the message on the pdfviewer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM