JSF DocumentViewer无法在@ViewScope中显示PDF
我对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。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请勿使用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
我最终撰写了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.