title: p:fileDownload bean method is invoked but file download does not show up
body: <p>Hello I'm doing File upload and download same file operation using JSF and Primefaces.</p>
  
  <p>I'm using techniques from different forums and blogs combined(BelusC 's blog and Primefaces Showcase).   </p>
  
  <blockquote>
    <p>The main idea of this operation is to let user to upload a file and
    generate a Download link for the uploaded file so that he can download
    and see it before Submitting.</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <p>index.xhtml</p>
  
  <pre><code>&lt;h:form&gt;
      &lt;p:fileUpload showButtons="false" label="Attach Refrral" 
          auto="true" fileUploadListener="#{fileBean.uploadListener}"/&gt;
  &lt;/h:form&gt;
  
  &lt;h:form &gt;
     &lt;p:commandLink&gt;
        See Uploaded File
        &lt;p:fileDownload value="#{fileBean.refrralFile}"/&gt;
     &lt;/p:commandLink&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>FileBean.java</p>
  
  <pre><code>private StreamedContent refrralFile;
  
  
      public void uploadListener(FileUploadEvent evt)throws Exception
      {
          UploadedFile fx = evt.getFile();
  
          File mainDir = new File("C:/","fileStorage");
          if(!mainDir.exists())
          {
              mainDir.mkdir();
          }
          File subDir = new File(mainDir,"AttachedRefrrals");
          if(!subDir.exists())
          {
              subDir.mkdir();
          }
          String fileName = fx.getFileName();
  
          File f = new File(subDir,fileName);
          FileOutputStream fos = new FileOutputStream(f);
          IOUtils.copy(fx.getInputstream(), fos);
  
          InputStream is = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream(f.getAbsolutePath());
          refrralFile  = new DefaultStreamedContent(is, new MimetypesFileTypeMap().getContentType(f), fileName);
  
      }
  
  
      public StreamedContent getRefrralFile() {
          return refrralFile;
      }
  </code></pre>
  
  <p>Using above code File is uploading Successfully but if I click file download link ths throwing exception: </p>
  
  <pre><code>java.lang.IllegalStateException: getOutputStream() has already been called for this response
  </code></pre>
  
  <p>I used <strong>FacesContext#responseComplete()</strong>, as its been suggested many places, now download link is not working at all.</p>
  
  <p>Please correct me if I'm wrong in my technique or code and suggest any better way if you know.</p>