1
How to make a simple JSF download?
I have a list of attachments on <p:dataTable>
and would like to implement a simple download.
I implemented with <a href>
, the link about the file name was created, but when I click it simply does not download.
I wouldn’t want to use any components like <p:fileDownload>
, because I need something very simple and the <p:fileDownload>
would have to create a logic to be able to identify the types: zip, xls, doc and etc.
Like I said, I tried <a href>
as below, the link appears but nothing happens when I click on the link:
<p:column headerText="Nome do Anexo" width="55%">
<a href="${cadastroAtividadeBean.defineCaminhoDownload(anexo.nomeAnexo)}"
title="${anexo.nomeAnexo}">
<h:outputText value="#{anexo.nomeAnexo}" />
</a>
</p:column>
Would anyone have any example that could help me?
Oops, I posted an answer, but I would like to ask a question, are you only having problems with the jsf part, or are you having problems with the Java part too? Because if so, put the java structure of my download method.
– WyllianNeo
Oops, I saw you didn’t disable ajax in your code. I don’t use href, but I couldn’t find parameters to activate and disable ajax in it, I think this may be your problem. If this is the case, let me know. I edited my reply to mention this point.
– WyllianNeo
What the method
defineCaminhoDownload
returns? A URL, a file path on the server?– utluiz
Marcelo, I suspended the question because we already have three answers that do not solve your problem, on the contrary, pass away. If you still need help, please rephrase the question and make it clearer exactly what is on this link than you do overall. Particularly, I think there is a misconception in this implementation, that is, it gives the impression that you want to generate a URL (link) for a local file on the server. This is not possible, have to have a code that reads the file and is exactly what the
<p:fileDownload>
ago.– utluiz
Another thing, with the
<p:fileDownload>
you do not need to make a logic for each file type (although this would be better for system usability). You can force the download of any file as in this answer.– utluiz