title: Close PrimeFaces dialog after OmniFaces sendFile
body: <p>I'm trying to create a <code>&lt;p:ajaxstatus /&gt;</code> like indicator when downloading a file using OmniFaces <code>Faces.sendFile</code> function. When the user clicks the Export link a dialog tells them the file is being created (because this can take sometime depending on the data size), then after the file downloads the message closes.</p>
  
  <p>In my xhtml:</p>
  
  <pre><code>&lt;p:dialog widgetVar="excelDialog" modal="true"&gt;
      &lt;h2&gt;Building Spreadsheet&lt;/h2&gt;
  &lt;/p:dialog&gt;
  
  &lt;h:commandLink value="Export" action="#{resultsBean.excelExport}" onclick="excelDialog.show();" /&gt;
  </code></pre>
  
  <p>and in my ViewScoped bean:</p>
  
  <pre><code>public void excelExport() throws IOException {
      ExcelExport ee = new ExcelExport(results);
      Faces.sendFile(ee.getFile(), true);
  }
  </code></pre>
  
  <p>What I can't figure is how I could close the dialog after the response is complete. </p>
  
  <p>I've tried using the PrimeFaces RequestContext (which should work for non-ajax requests) but does not work.  I wonder if this is because <code>Faces.sendFile</code> calls <code>FacesContext.responseComplete()</code> before the RequestContext is used. </p>
  
  <pre><code>public void excelExport() throws IOException {
      ExcelExport ee = new ExcelExport(results);
      Faces.sendFile(ee.getFile(), true);
      RequestContext c = RequestContext.getCurrentInstance();        
      c.execute("PF('excelDialog').hide();");       
  } 
  </code></pre>
  
  <ul>
  <li>JSF 2.1 </li>
  <li>PrimeFaces 4.0 </li>
  <li>OmniFaces 1.8</li>
  </ul>