【问题标题】:primefaces streamedContent and p:media does not update contentsprimefaces streamedContent 和 p:media 不更新内容
【发布时间】:2018-06-15 18:36:16
【问题描述】:

大家好,

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

我的目标:显示与表格中的项目关联的pdf

问题:当我第一次单击要显示的 pdf 时,它实际上会呈现,但是当我想查看另一个 pdf 时,它总是显示我选择的第一个.

如果我第一次开始一切,并且如果我点击最后一项,则表明:

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

第三个 pdf 有不同的文档(我很确定)

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

我的 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()"/>                                                
                        <br/>
                        <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>

豆

@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;
    }

}

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    出现这种情况是因为 Web 客户端已经缓存了流并且只在一段时间后才刷新它。

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

    【讨论】:

    • 此解决方案也可以应用于 。
    猜你喜欢
    • 2013-09-30
    • 2012-01-25
    • 2011-11-10
    • 2013-01-07
    • 2014-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多