Primefaces 扩展文档查看器显示下载状态
Primefaces extensions documentViewer show download status
我使用 primefaces 扩展文档查看器来显示 pdf。文件是流式传输的,这意味着支持 bean 提供了 org.primefaces.model.DefaultStreamedContent
的实例。如果显示大 pdf,则查看器需要一些时间才能显示某些内容。在 PF 扩展网站的展示中,documentViewer
在查看器按钮栏下方显示了一个加载栏。不幸的是,这在我的案例中没有显示。在展示中没有使用 DefaultStreamContent
。归档是url。也许我必须设置流媒体内容的总大小? DefaultStreamedContent
可以吗?
Maybe I have to set the total size for the streamed content
是的!客户端只有在事先知道响应内容长度的情况下才能计算进度。在 JSF 中,您可以通过 ExternalContext#setResponseContentLength()
.
设置响应内容长度
假设您想要 return 一个 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());
}
}
}
我使用 primefaces 扩展文档查看器来显示 pdf。文件是流式传输的,这意味着支持 bean 提供了 org.primefaces.model.DefaultStreamedContent
的实例。如果显示大 pdf,则查看器需要一些时间才能显示某些内容。在 PF 扩展网站的展示中,documentViewer
在查看器按钮栏下方显示了一个加载栏。不幸的是,这在我的案例中没有显示。在展示中没有使用 DefaultStreamContent
。归档是url。也许我必须设置流媒体内容的总大小? DefaultStreamedContent
可以吗?
Maybe I have to set the total size for the streamed content
是的!客户端只有在事先知道响应内容长度的情况下才能计算进度。在 JSF 中,您可以通过 ExternalContext#setResponseContentLength()
.
假设您想要 return 一个 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());
}
}
}