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));
}