JSF DocumentViewer无法在@ViewScope中显示PDF

发布于 2025-01-25 01:19:52 字数 639 浏览 3 评论 0 原文

我对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。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很糊涂小朋友 2025-02-01 01:19:52

请勿使用pdfviewer使用viewScoped使用requestScoped/sessionscoped/applicationscoped。

请参阅: https://github.com/github.com/primefaces-extensions/ primefaces-extensions.github.com/issues/796

balusc解释了为什么不能使用ViewScoped:

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

吃素的狼 2025-02-01 01:19:52

我最终撰写了JS以实现欲望结果。 JS监视了PDFViewer,如果它未能加载文档,我在PDFViewer上更新了该消息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文