2 Replies Latest reply on Sep 27, 2007 5:34 AM by Marcelo Krebber

    PDF download with richfaces wont work

    Marcelo Krebber Newbie

      hi, the following

      <h:commandLink immediate="true" style="cursor:pointer"
       actionListener="#{mybean.showPDF}" >
       <h:graphicImage value="adobe.gif" />
       <f:attribute name="param1" value="#{element.paramone}" />
       <f:attribute name="param2" value="#{element.paramtwo}" />
      </h:commandLink>
      


      works correctly. the backingbean method showPDF produces some pdf and writes it into the response outputstream. the browser recognizes the pdf and starts the adobe application to show it.

      however, if i change the above to use
      <a4j:commandLink>.. </a4j:commandLink>
      
      or
      
      <a4j:commandButton>..</a4j:commandButton>
      


      the browser doesnt recognize the pdf document at all and tries to display it as regular html in a separate page!...

      any idea what im doing wrong?
      thanks. marcelo

        • 1. Re: PDF download with richfaces wont work
          Mikael Andersson Master

          Hi,
          are you setting the correct content type in the action?

          I'm also a bit curious about why you want to use the a4j components for this?

          Cheers

          • 2. Re: PDF download with richfaces wont work
            Marcelo Krebber Newbie

            yes, that is working right, like

             ..
             byte[]pdf = getPDF();
             FacesContext faces = FacesContext.getCurrentInstance();
             HttpServletResponse response = (HttpServletResponse) faces
             .getExternalContext().getResponse();
            
             response.setContentType("application/pdf");
             response.setContentLength(pdf.length);
             response.setHeader("Content-disposition", "attachment; filename="
             + "mypdf.pdf");
            
             response.getOutputStream().write(pdf);
             faces.responseComplete();
             ..
            


            since the tags with <h:commandLink..> works correctly. it is just when i chnage the tags to <a4j:..> that it fails.

            the reason i need an ajax call is to start something like a progress bar while the pdf is downloading.

            marcelo