jsfprimefacesprimefaces-extensions

Load content in Primefaces Extensions documentViewer


I'm loading StreamedContent into the document viewer like this.

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>

Bean:

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

Question: Is there any way to change the document in the viewer without update the whole component?


Solution

  • using:

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

    instead of

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

    works for me.