Commandlink won't start downloading a file generated with XDocReport

33 Views Asked by At

I came accross this problem in a current project using XDocReport to generate different files from a database. It's been days of failing attempts now.

Here is the deal : I have my bean with a downloadPptx method that is used to generate and start download of a pptx report of some datas. I call it from a commandlink that I suppose should start the download when I click it, but actually doesn't.

I followed several guides from BalusC all over stackoverflow including this one or this other one but never got it to start downloading. The method, though, is called on click, as I have some logs showing up.

Here's extracts of my code :

public void downloadPptx() {

    IXDocReport doc = null;
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    int idRef = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("ref"));
    String fileName = idRef+".pptx";

    try {

        // [...] Generating document with XDocReport

        ec.responseReset(); 
        ec.setResponseContentType("application/vnd.openxmlformats-officedocument.presentationml.presentation");
        ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); 

        doc.process(context, ec.getResponseOutputStream());

        fc.responseComplete(); 

    } catch (XDocReportException e) {
        log.debug(e.getMessage());
    } catch (IOException e) {
        log.debug(e.getMessage());
    }


}

This is my bean's method (a bit cleaned up from unrevelant things), and here's an extract of my page :

<p:commandLink action="#{viewRef.downloadPptx}" immediate="true">
    <p:graphicImage url="ressources/img/ppt.png" />
    <f:param name="ref" value="#{viewRef.reference.idRef}"/>
</p:commandLink>

I tried several things, from using a buffer to transfer, to using ajax in the web page, but nothing seems to work, I must be missing or misunderstanding something I guess. I also tried to generate a text/plain file but it changed nothing.

0

There are 0 best solutions below