9 Replies Latest reply on May 2, 2007 2:21 PM by robjellinghaus

    issue with itext pdf generation and JSF RI

    borisrodman

      I'm using seam 1.2.1.GA
      Since I switched to using JSF RI, the redirection to the seam generated PDF fails:

      I took the seam-itext example from the 1.2.1.GA release
      and applied the step 1.11 of the seam user manual "Running the Seam examples in JBoss using the JSF 1.2 RI" on that project:

      when i run the example and click on a link to see a pdf, my browser returns:


      This XML file does not appear to have any style information associated with it. The document tree is shown below.
      
      <html>
      <head>
      <meta http-equiv="Refresh" content="0; URL=whyseam.pdf?docId=1&conversationId=2"/>
      </head>
      <body/>
      </html>


      Has anyone had the same issue ? or any idea how to fix this ?
      thanks for you replies


        • 1. Re: issue with itext pdf generation and JSF RI
          jdestef

          Hi,

          Are you using FireFox? I have a similar issue. The application can display the pdf fine when using internet explorer but I get the same message you do with FireFox. At least in my case it looks like FireFox thinks the response is an XML doc?

          Tx

          • 2. Re: issue with itext pdf generation and JSF RI
            jdestef

            Hi,

            From posting above I'm using Firefox ver 2.0.0.3. I ran the itext demo from CVS (today) and I get the same issue. Running in i.e. works fine.

            Tx

            • 3. Re: issue with itext pdf generation and JSF RI
              borisrodman

              Hi

              I managed to find the issue:
              in the UIdocument class seam forward to a page that redirect to the PDF document:
              the page rendered has no Doctype specified and the MIME return type is set to XML/Application (or something similar) therefore firefox doesn't know what to do with it.
              A agree with you that it doesn't bother IE

              to fix the issue you must change the class:
              (jboss-seam-1.2.1.GA\src\pdf)
              org.jboss.seam.pdf.ui.UIDocument to output a doctype:

              in the medhod: public void encodeBegin(FacesContext context)
              replace the following lines (from line 233):

               ResponseWriter response = context.getResponseWriter();
               response.startElement("html", this);
               response.startElement("head", this);

              by
               ResponseWriter response = context.getResponseWriter();
               response.write("<!DOCTYPE composition PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\" >");
               response.startElement("html", this);
               response.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml", null);
               response.startElement("head", this);



              then recompile seam using the std build file (this will also recompile jboss-seam-pdf.jar where this class ends-up)
              and replace jboss-seam-pdf.jar in your project by the re-compiled jar

              It SHOULD work ! (At leasts it does for me)

              Also note that if you use the source code from CVS the jboss.jpg image in the itext example was corrupted last week which resulted in the PDF rendering to fail. (I don't know if this has been corrected since then)

              Let me know if you have any issues !

              • 4. Re: issue with itext pdf generation and JSF RI

                Have you opened a JIRA on this one? I'm still getting the same problem you described. BTW, it only shows up in RI - MyFaces 1.1.4 works fine

                • 5. Re: issue with itext pdf generation and JSF RI
                  robjellinghaus

                  I would expect the Seam team to have to fix this for Seam 1.3, when the RI will become the standard Seam JSF implementation. The problem is definitely that the RI more often emits a content-type of application/xhtml+xml for XHTML pages, which Firefox tries to parse as XHTML. Arguably this is just bad -- it actually breaks GWT, for instance, and XHTML 2.0 seems to be dead in the water.

                  In Facelets you can add a wrapper f:view tag with attribute contentType="text/html" to override this in some situations. Not sure if this will work for the itext PDF pages, but it might be worth a shot.

                  • 6. Re: issue with itext pdf generation and JSF RI

                    f:view doesn't have a contentType attribute, sorry.

                    And for some reason I don't have the ability to open JIRA issues. Damn.

                    borisrodman's suggestion works, though - one doesn't even need to recompile the whole source, just place the corrected class in the project, it will automatically take precedence for the one in Seam JAR.

                    • 7. Re: issue with itext pdf generation and JSF RI
                      christian.bauer

                      <f:view contentType="text/html"/> works for Facelet templates, even if your XML validator in your IDE says it doesn't.

                      • 8. Re: issue with itext pdf generation and JSF RI

                        Whoa, it worked! Thanks Rob & Christian :)

                        (actually, it's the JSF specs that I checked for the contentType attribute - for some reason it's not listed even there...)

                        • 9. Re: issue with itext pdf generation and JSF RI
                          robjellinghaus

                          It's a Facelets feature, I think. Google for "Facelets content-type FAQ" and it'll turn up.