downloading file prevents facesmessage to appear
arnieaustin.arnie.morein.me.com Jun 21, 2009 11:58 PMI have a Seam 2.1.2 app that generates reports. All output is via PDF files which I'm generating directly by the iText APIs. After generation, the PDF file is downloaded to the workstation and Acrobat Reader takes over.
The odd thing I cannot get to work right is the appearance of a message ('report completed') if I allow the download to proceed. E.g:
if ( renderReport() ) { facesMessages.add(Severity.INFO, "#{messages['global.reportCompleted']}"); downloadReportFile(); } else { facesMessages.add(Severity.ERROR, "#{messages['global.reportError']}"); }
If I comment out the downloadReportFile();
line, the message appears as expected. But if I allow the download, it doesn't. The file downloads just fine and the application continues to operate without issue.
The download code is pretty straight forward. I got the download method from here I believe, or maybe else where; it doesn't matter.
But it clearly is interfering with Seam's processing or cache. It is listed below. Is there something I can do before calling it to make sure the message gets processed?
Thanks!
public Boolean download() { Boolean result = false; HttpServletResponse response = (HttpServletResponse)extCtx.getResponse(); response.setContentType("application/pdf"); response.addHeader("Content-disposition", "attachment; filename=\"" + fileName +"\""); //Now we create some variables we will use for writing the file to the response int read = 0; byte[] bytes = new byte[1024]; //Streams we will use to read, write the file bytes to our response FileInputStream fis = null; File file = null; try { ServletOutputStream os = response.getOutputStream(); //First we load the file in our InputStream try { file = new File(fileName); fis = new FileInputStream(file); os = response.getOutputStream(); //While there are still bytes in the file, read them and write them to our OutputStream while((read = fis.read(bytes)) != -1){ os.write(bytes,0,read); } //Clean resources os.flush(); os.close(); file.delete(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } os.flush(); os.close(); facesContext.responseComplete(); result = true; } catch(Exception e) { log.error("\nFailure : " + e.toString() + "\n"); } return result; }