title: Primefaces filedownload error handling
body: <p>How to handle error with primefaces filedownload</p>
  
  <pre><code>&lt;p:fileDownload value="#{testBean.file}" /&gt; 
  </code></pre>
  
  <p>TestBean.java</p>
  
  <pre><code>    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"); 
      }
  </code></pre>