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}" />

      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>

      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

          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?


          • 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
             response.setHeader("Content-disposition", "attachment; filename="
             + "mypdf.pdf");

            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.