question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileDownload/CommandButton inside facet of a datatable, not working at all

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
qoelhexcommented, Jul 19, 2022

Oh boys, @tandraschko and @melloware , you rock!

1reaction
tandraschkocommented, Jul 19, 2022

@melloware can we improve the docs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

command button not working inside datatable in JSF 1.2
When I am creating datatable in a .jspx file the data is displaying but when I add any inside datatable the button doesn't...
Read more >
DataTable contains empty header when header facet content ...
With my proposed fix in the renderer, this would result in no header row being rendered at all if #{not empty headerText} evaluates...
Read more >
dataTable and commandLink not working together
Hi, I have the following data table:<h:dataTable value="#{userSearch.userList}" var="user" headerClass="dataTableHeader" rowClasses="oddRow ...
Read more >
JSF 2 dataTable example - Mkyong.com
The following JSF 2.0 example show you how to use “h:dataTable” tag to loop over an array of “order” object, and display it...
Read more >
6.6.14. < rich:scrollableDataTable > available since 3.1.0
In this case all the rows starting from last selected up to clicked should be selected. It's possible to sort the table content...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found