首页 文章

primefaces streamedContent和p:media不更新内容

提问于
浏览
0

Hello everyone,

我试图从dataTable中显示不同的pdf,但这是不可能的

My goal: 显示与表格中的项目相关联的pdf

The problem: 当我第一次点击我想要显示的pdf时,它实际呈现,但是当我想看到另一个pdf时,它总是显示我选择的第一个 .

如果我是第一次启动所有内容,如果我点击最后一项,则显示:

enter image description here

如果我想显示第三个pdf,它会显示:

enter image description here

第三个pdf有一个不同的文件(我非常肯定)

我已经阅读了这个Display dynamic image from database with p:graphicImage and StreamedContent,但我找不到解决方案,因为我使用了一个对话框,我无法正确使用f参数

My Code XHTML:

<p:dataTable var="documento" value="#{docController.obtenerDocumentos()}" 
                     ...
                     filteredValue="#{docController.filteredValue}"
                     >

            ......
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Acciones"/>
                </f:facet>
                <h:form>
                    <center>
**here I send the document to be shown in the bean**
                        <p:commandButton styleClass="ui-priority-primary" icon="fa fas fa-eye" update=":visualizacion" action="#{visualizarDocumento.verDocumento(documento)}" value="Ver documento" onstart="PF('cargando').show()"  onsuccess="PF('cargando').hide()"/>                                                
                        
<p:commandButton styleClass="ui-priority-primary" icon="fa fas fa-align-justify" action="#{docController.respuestaDocumento(documento)}" value="Ver respuestas"/> </center> </h:form> </p:column> </p:dataTable> <p:dialog widgetVar="visualizarPDF" modal="true"> <h:form id="visualizacion" > <p:media value="#{visualizarDocumento.streamedContent}" width="750" height="560" player="pdf" /> </h:form> </p:dialog>

BEAN

@Named(value = "visualizarDocumento")
@Stateless
public class VisualizarDocumentoController {
    private StreamedContent streamedContent;
    InformacionDocumento doc;

    public void verDocumento(InformacionDocumento documento) { 
        doc=documento;
        byte[] decode = Base64.getDecoder().decode(doc.getArchivo().getBase64());
        ByteArrayInputStream bis = new ByteArrayInputStream(decode);
        streamedContent = new DefaultStreamedContent(bis, "application/pdf");
        RequestContext requestContext = RequestContext.getCurrentInstance();
        requestContext.update(":visualizacion");
        requestContext.execute("PF('visualizarPDF').show()");
    }

    public StreamedContent getStreamedContent() {
        return streamedContent;
    }

    public void setStreamedContent(StreamedContent streamedContent) {
        this.streamedContent = streamedContent;
    }

}

1 回答

  • 1

    发生这种情况是因为Web客户端已缓存流并且仅在一段时间后刷新它 .

    在p:media元素中添加属性cache =“false”以强制Web客户端每次刷新“visualizarPDF”时重新加载流 .

相关问题