我使用primefaces扩展documentViewer来显示pdfs。文件是流的,这意味着backing提供了一个org.primefaces.model.DefaultStreamedContent实例。如果一个大的pdf显示,它需要一些时间,直到观众显示了一些东西。在PF扩展网站的展示中,documentViewer在查看器按钮栏下显示一个加载栏。不幸的是,这一点在我的例子中没有体现出来。在展示中没有使用DefaultStreamContent。这是要归档的网址。也许我必须设置流媒体内容的总大小?有可能用DefaultStreamedContent吗?
发布于 2015-11-06 10:52:51
也许我必须设置流内容的总大小。
是!客户端只能在事先知道响应内容长度的情况下才能计算进度。在JSF中,可以通过ExternalContext#setResponseContentLength()设置响应内容长度。
如果您想返回一个StreamedContent,那么您可以这样做(基于a.o )。Display dynamic image from database with p:graphicImage and StreamedContent):
@ManagedBean
@ApplicationScoped
public class PdfManager {
@EJB
private PdfService service;
public StreamedContent getContent() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
return new DefaultStreamedContent();
} else {
Pdf pdf = service.generateItSomehow();
context.getExternalContext().setResponseContentLength(pdf.getLength());
return new DefaultStreamedContent(pdf.getInputStream());
}
}
}https://stackoverflow.com/questions/33522321
复制相似问题