1

I am trying to download files (send them to browser) using primefaces filedownload. For some reason it does not send the file to the browser. The pop-up dialog I am using the p:filedownload in shows up when clicking on the button on my page. I already saw this: p:fileDownload bean method is invoked but file download does not show up but the problem is that I need to set the file in the bean by calling the action when the user picks the fileName to download:

test.xhtml

<p:dialog>
    <p:dataTable var="currentAttachment" value="#{managerBean.attachmentsForPatient()}">
      <p:column>
        <p:commandLink value="#{currentAttachment.name}"  action="#{managerBean.downloadAttachment(currentAttachment)}">
          <p:fileDownload value="#{managerBean.file}" />  
        </p:commandLink>
      </p:column>
    </p:dataTable>
</p:dialog>

managerBean.java

public void downloadAttachment(Attachment attachment) throws IOException {
    InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream(attachment.getContent().toString());  
    setFile(new DefaultStreamedContent(stream)); 
}
Community
  • 1
  • 1
Denorm
  • 466
  • 4
  • 13

1 Answers1

1

Please check your web.xml for correct configuration. Sample is posted here..

<filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

Also check that the following dependencies are added

commons-fileupload*.jar,commons-io*.jar

This should help.

satya
  • 164
  • 1
  • 8
  • 1
    You're confusing "download" with "upload". Why this answer is accepted is totally beyond me. – BalusC Mar 14 '15 at 19:10