首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Primefaces扩展documentViewer显示下载状态

Primefaces扩展documentViewer显示下载状态
EN

Stack Overflow用户
提问于 2015-11-04 12:45:14
回答 1查看 1.1K关注 0票数 2

我使用primefaces扩展documentViewer来显示pdfs。文件是流的,这意味着backing提供了一个org.primefaces.model.DefaultStreamedContent实例。如果一个大的pdf显示,它需要一些时间,直到观众显示了一些东西。在PF扩展网站的展示中,documentViewer在查看器按钮栏下显示一个加载栏。不幸的是,这一点在我的例子中没有体现出来。在展示中没有使用DefaultStreamContent。这是要归档的网址。也许我必须设置流媒体内容的总大小?有可能用DefaultStreamedContent吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-06 10:52:51

也许我必须设置流内容的总大小。

是!客户端只能在事先知道响应内容长度的情况下才能计算进度。在JSF中,可以通过ExternalContext#setResponseContentLength()设置响应内容长度。

如果您想返回一个StreamedContent,那么您可以这样做(基于a.o )。Display dynamic image from database with p:graphicImage and StreamedContent):

代码语言:javascript
复制
@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());
        }
    }

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33522321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档