我使用了来自primefaces的documentViewer-component扩展,如下所示:
<pe:documentViewer cache="true" value="#{myBean.streamedContent}"/> myBean是SessionScoped。
如果我重新加载页面,则会调用getter,并且streamedContent不为空,但查看器会显示一个空页面和消息stream must have data。
如何在页面重新加载时在查看器中恢复文档?
发布于 2016-08-18 22:35:58
我用PrimeFaces Extensions Showcase重现了你的问题,所以我用了下面的代码
ByteArrayOutputStream out = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter.getInstance(document, out);
document.open();
for (int i = 0; i < 50; i++) {
document.add(new Paragraph("All work and no play makes Jack a dull boy"));
}
document.close();
content = new DefaultStreamedContent(new ByteArrayInputStream(out.toByteArray()), "application/pdf");但我找到了一个解决方案。问题只存在于使用DefaultStreamedContent,但当我检查了层次结构时,我发现使用ByteArrayContent也是可行的。即使在页面重新加载之后,它也能正常工作。
示例用法:
content = new ByteArrayContent(out.toByteArray(), "application/pdf");https://stackoverflow.com/questions/38956285
复制相似问题