【发布时间】: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