'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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1