首页 > 解决方案 > 在 Primefaces Extensions documentViewer 中加载内容

问题描述

我正在像这样将 StreamedContent 加载到文档查看器中。

xhtml:

<h:body>
    <h:form>
        <p:commandButton value="Content A" action="#{viewer.selectContentA()}" update="viewerForm" />
        <p:commandButton value="Content B" action="#{viewer.selectContentB()}" update="viewerForm" />
    </h:form>
    <h:form id="viewerForm">
        <pe:documentViewer value="#{viewer.content}" download="demo.pdf" height="500"/>
    </h:form>
</h:body>

豆:

public void selectContentA() {
    content = contentA;
}
public void selectContentB() {
    content = contentB;
}
public StreamedContent getContent() {
    return content;
}

问题: 有没有办法在不更新整个组件的情况下更改查看器中的文档?

标签: jsfprimefacesprimefaces-extensions

解决方案


使用:

function refresh() {
     document.getElementById('viewerForm:viewer').contentDocument.location.reload();
}
<p:commandButton value="Load document" ... oncomplete="refresh()" />

代替

<p:commandButton` value="Load document" ...  update="viewerForm:viewer" />

为我工作。


推荐阅读