You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Carl Howarth <ca...@dlapiper.com> on 2007/11/21 09:48:06 UTC

IE File download prompt with commandlink

Hello,

It's now over a year on and I've come back to this problem in a project that
I am working on. I am creating a PDF, and am having issues with Internet
Explorer 6. If I use a command link the pdf downloads successfully, but then
any subsequent command link I select prompts me to download the file again.
I have trawled the web in order to find an answer but am still stumped. As
before the download works without an issue in Firefox.

I am now using MyFaces 1.2.0, Tomahawk 1.1.6 and also have Richfaces 3.1.2.
I am running on Tomcat 6.0.14.

Surely this is a bug in the command link?

Here is my commandlink:

<t:commandLink value="Download PDF" rendered="#{!
maintainPurchaseOrderBean.editPOItemsMode}"
actionListener="#{maintainPurchaseOrderBean.downloadPO}" />

Here is my code, I have added the various cache control headers in an
attempt to fix the problem but to no avail:

  public void downloadPO(ActionEvent ev) {
        _log.debug("Downloading PO");
        FacesContext fc = FacesContext.getCurrentInstance();
        try {
            HttpServletRequest req = (HttpServletRequest)
fc.getExternalContext().getRequest();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            HttpServletResponse response = (HttpServletResponse)
fc.getExternalContext().getResponse();
            StateManager stateManager = (StateManager)
fc.getApplication().getStateManager();

            _purchaseOrderService.generatePurchaseOrderDownload(baos,
_purchaseOrder);

            response.setHeader("Content-disposition", "attachment;
filename=\"" + _purchaseOrder.getId() + ".pdf\"");
            response.setContentType("application/pdf");
            response.setContentLength(baos.size());
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Cache-Control", "max-age=0");
            response.setHeader("Pragma", "no-cache");

            baos.writeTo(response.getOutputStream());

            response.getOutputStream().flush();
            response.getOutputStream().close();
            response.flushBuffer();

            stateManager.saveSerializedView(fc);
            fc.responseComplete();
        } catch (IOException e) {
            fc.addMessage(null, new
FacesMessage(FacesMessage.SEVERITY_ERROR, "Error downloading PDF", null));
            _log.error(e);
        }
    }

Has anybody got a solution for this issue? I look forward to hearing one!

Many thanks, Carl 
-- 
View this message in context: http://www.nabble.com/IE-File-download-prompt-with-commandlink-tf4848788.html#a13873162
Sent from the My Faces - Dev mailing list archive at Nabble.com.