I'm trying to make use of the p:fileDownload
component of primefaces.
<p:commandButton value="Download" ajax="false" icon="ui-icon-arrowthick-1-s">
<p:fileDownload value="#{fileDownloadView.file}" />
</p:commandButton>
ManageBean:
@ManagedBean
public class FileDownloadView {
private StreamedContent file;
public FileDownloadView() {
InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream("C:\Users\Yo\Desktop\excel.xlsx");
file = new DefaultStreamedContent(stream, "application/vnd.ms-excel", "docu.xlsx");
}
public StreamedContent getFile() {
return file;
}
}
The problem is in the line InputStream stream...
I have debugged it and I get null
. I've also tried as specified in primefaces.org
:
InputStream stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("C:\Users\yo\Excel.xlsx");
Do you know what the reason may be?