Hello everyone,
I'm trying to show different pdfs from dataTable but that's impossible
My goal: Show the pdf associated with the item in the table
The problem: When I click for the first time on a pdf that I want to show, it actually renders, but when I want to see another pdf it always shows the first one that I select.
If I start everything for the first time, and if I click in the last item, shown that:
If I want to show the third pdf, it shows:
and the third pdf has a different document (I am very sure of that)
I have read this Display dynamic image from database with p:graphicImage and StreamedContent , but I have not been able to find the solution, because I use a dialog and I could not use a f param correctly
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()"/>
<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>
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;
}
}