0 Replies Latest reply on Dec 13, 2007 1:18 PM by Phil Haigh

    changing response headers to modify filename for excel

    Phil Haigh Novice

      Hi,

      I'm trying to open a report in Excel, with a specified dynamic filename

      I have an xhtml page that spits out simple tabulated data. On viewing that page ID I call a method from pages.xml that does this:

      String fileName="Charity_Report"+i+".xls";
      
      HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
      response.setContentType("application/vnd.ms-excel");
      response.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\"");
      ctx.renderResponse();


      This works... the report is generated correctly, and with the right filename etc. However, intermittently, the spreadsheet that opens will have both the report that just ran, and the previous one in it! (I should mention there are several different report pages, with different filenames - set up exactly the same as above).

      It appears perhaps the response is not closing or something like that??

      I tried this:

      // TODO This is such a hack it's untrue (closes response after 5s)
      maintenanceTasks.endResponse(5000L,ctx);


      but although it doesn't seem to do any harm, it doesn't fix the intermittent problem.

      any ideas?

      cheers

      phil