0

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.

Community
  • 1
  • 1
MattOnyx
  • 172
  • 12
  • As I'm not showing any of the JPA code I removed the tag as you suggested. Also I tried to generate a `text/plain` file using a string converted to bytes, and it changed nothing. Still no download triggered while the method is called. – MattOnyx Feb 16 '16 at 12:52
  • So it is also not xdocreport related?, please improve your question then... (these are all steps in creating an [mcve] that can and should be done upfront, it makes the problem easier to see and even to find duplicates) – Kukeltje Feb 16 '16 at 13:12
  • Check https://stackoverflow.com/questions/9391838 for being a possible duplicate – Kukeltje Feb 16 '16 at 13:14
  • 1
    If it also does **not** work with text/plain from a byte[], it is **not** xdocreport related. And read the 'duplicate' I posted and check the part with the header that contains 'Ajax' – Kukeltje Feb 16 '16 at 13:22
  • The part of the BalusC guide about ajax was indeed the answer, my mistake was that I didn't realised that this part of the code was using primefaces, so I skipped over it. For futur readers, the answer was using `ajax="false"` in the commandlink. Thank you @Kukeltje for pointing this out! – MattOnyx Feb 16 '16 at 13:39

0 Answers0