1

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.

Melloware
  • 10,435
  • 2
  • 32
  • 62
  • Also don't use ViewScope with PDFViewer see this ticket for why: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/796 – Melloware May 07 '22 at 17:08

2 Answers2

0

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

Melloware
  • 10,435
  • 2
  • 32
  • 62
0

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.