How to handle error with primefaces filedownload
<p:fileDownload value="#{testBean.file}" />
TestBean.java
public StreamedContent getFile() {
if(selectedReport ==null){
FacesContext.getCurrentInstance().addMessage(.."Please select a file");
return null;//What to do here
}
InputStream inps = ReportGenerator.getPDF(selectedReport);
return new DefaultStreamedContent(inps, "application/pdf", "report.pdf");
}