FileDownload/CommandButton inside facet of a datatable, not working at all
See original GitHub issueDescribe the bug
In a dataTable I have facets for input and output. In a Blob field, for documents, I render a column with fileupload for input, all working there, and for output I render a commandButton with a fileDownload, no way to make it work.
If I go for the actionListener route to prepare the Stream prior to be called by the filedownload component, it doesnt fire at all the actionlistener. Using process=“@this” makes the actionlistenerr work, but crashes without throwing any error.
If I try to process the blob and create de stream direct in the method called by the filedownload, nothing happens.
This is the relevant sourc excerpt:
<p:column headerText="Documento">
<p:cellEditor id="conteudo">
<f:facet name="output">
<p:commandButton
value="Baixar o documento"
icon="pi pi-arrow-down"
styleClass="ui-button-outlined"
ajax="false">
<p:fileDownload value="#{cadastroEventoController.arquivo}"/>
</p:commandButton>
</f:facet>
<f:facet name="input">
<p:fileUpload listener="#{cadastroEventoController.trataUploadDeDocumento}"
mode="advanced" dragDropSupport="false"
update="dtDocumentos msgs" sizeLimit="100000000"
value="#{cadastroEventoController.arquivo}"
fileLimit="1" >
</p:fileUpload>
</f:facet>
</p:cellEditor>
</p:column>
Using ActionListener
<p:commandButton
value="Baixar o documento"
icon="pi pi-arrow-down"
styleClass="ui-button-outlined"
process="@this"
actionListener="#{cadastroEventoController.preparaArquivo()}"
ajax="false">
<p:fileDownload value="#{cadastroEventoController.arquivo}"/>
</p:commandButton>
Relevant methods:
// In Case direct use by filedownload
public StreamedContent getArquivo() {
FacesContext context = FacesContext.getCurrentInstance();
Integer linha = context.getApplication().evaluateExpressionGet(context, "#{linha}",Integer.class);
DocumentoEntity doc = eventoDTO.getObjeto().getDocumentos().get(linha);
ByteArrayInputStream stream = new ByteArrayInputStream(doc.getConteudo());
return new DefaultStreamedContent(stream, doc.getMime(), doc.getLegenda() + "." + doc.getExtensao());
}
// In Case ActionListener works
public void preparaArquivo() {
FacesContext context = FacesContext.getCurrentInstance();
Integer linha = context.getApplication().evaluateExpressionGet(context, "#{linha}",Integer.class);
DocumentoEntity doc = eventoDTO.getObjeto().getDocumentos().get(linha);
ByteArrayInputStream stream = new ByteArrayInputStream(doc.getConteudo());
setArquivo(new DefaultStreamedContent(stream, doc.getMime(), doc.getLegenda() + "." + doc.getExtensao()));
}
Extracting the CommandButton from the dataTable, but still inside the form, passing the index, makes any approach works to download the correct blob.
Reproducer
No response
Expected behavior
I would expect the FileDownload, inside a CommandButton, inside a dataTable, to try to get de BLOB contents through the provided attribute and initiate the download. Behavior that works perfectly outside the dataTable.
PrimeFaces edition
Elite
PrimeFaces version
8.0.16
Theme
No response
JSF implementation
No response
JSF version
2.3
Browser(s)
No response
Issue Analytics
- State:
- Created a year ago
- Comments:10 (6 by maintainers)
Oh boys, @tandraschko and @melloware , you rock!
@melloware can we improve the docs?