title: Downloading file during p:ajax rowSelect event in p:dataTable
body: <p>I want to download a document file by row click on primefaces datatable. I tried to call the action from Bean by using ajax like this:</p>
  
  <pre><code>&lt;p:dataTable
              id="docId"
              value="#{testBean.document}"
              var="doc"
              selectionMode="single"
              selection="#{testBean.selectedDoc}"
              &gt;
  
              &lt;p:ajax event="rowSelect" listener="#{testBean.actionDownload}"/&gt;
  
              &lt;p:column&gt;
                  ...
              &lt;/p:column&gt;
                  ...
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>But the following code does not execute what I want. The logic of my action is correct. But seems so that the downloading document does not work with ajax Request. There is no reaction and the download does not executed.</p>
  
  <pre><code>public String actionDownload() {
      try {
          FacesContext facesContext = FacesContext.getCurrentInstance();
          HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
  
          StringBuffer contentDisposition = new StringBuffer();
          contentDisposition.append("attachment;");
          contentDisposition.append("filename=\"");
          contentDisposition.append(name);
          contentDisposition.append("\"");
  
          response.reset();
          response.setContentType("application/x-download");
  
          response.setHeader("Content-Disposition", contentDisposition.toString());
          ServletOutputStream out = response.getOutputStream();
          response.setContentType("application/x-download");
          out.write(output);
          out.close();
      } catch (IOException e) {
          System.out.println(e.getMessage());
      }
      FacesContext.getCurrentInstance().responseComplete();
      return null;
  }
  </code></pre>
  
  <p>Is there an alternative to download a file by click on Datatable row?</p>