• Stop file download dialog - just generate file and execute script in postGeneration

    By Damien P Soward 2 years ago


    Is there any way to prevent the file download dialog from showing with an Excel export? I'm trying to generate the file and work on it in postGeneration with the “workbook” variable.

    Thanks very much

    • By Damien P Soward 2 years ago

      Currently my code in postGeneration is running fine and attaching a workbook to a notes document.

      However, I've found that the export is crashing when it tries to send the output file to the browser. No download dialog pops up, but the page says it's trying to connect with server, and then times out with a 504 error after about a minute.

      Is there a way to stop or interrupt POI at the end of postGeneration (and to not hand the file ouput to the browser) to get around this??

      Thanks Christian

    • By Damien P Soward 2 years ago


      Inow have a bit more information about what is causing the error on my end. Hopefully someone can point in the right direction about how to write the generated workbook to a stream.

      My code falls apart on the following line: a.write(bos).
      This gives the error java.lang.IllegalStateException: Cannot use PrintWriter while ServletOutputStream is in use

      CODE in postGenerationProcess:

      FacesContext context = FacesContext.getCurrentInstance();
      Session session = (Session) context.getApplication().getVariableResolver().resolveVariable(context, “session”);

      Stream stream = session.createStream();
      ByteArrayOutputStream bos = new ByteArrayOutputStream();


      // Convert the output stream to an input stream
      InputStream is = new ByteArrayInputStream(bos.toByteArray());

      Thanks very much. Any assistance is greatly appreciated