myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Howarth <carl.howa...@dlapiper.com>
Subject Re: commandLink commandButton differences in file download behaviour problem
Date Tue, 20 Nov 2007 14:47:38 GMT

Hello again,

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 now creating a PDF, and am still 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.

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/commandLink-commandButton-differences-in-file-download-behaviour-problem-tf2375460.html#a13858353
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Mime
View raw message