6 Replies Latest reply on Nov 26, 2007 4:14 AM by Sebastian Stenerdal

    iText PDF not working with DocumentStore and SeamServletFilt

    Waseem Quraishi Newbie

      Hello all,

      I'm relatively new to SEAM and was experiencing a problem using the iText library. I was able to successfully get a PDF to render by putting the pdf (p:XXXX) code directly inline into my .xhtml page. I wanted this to work by generating links and allowing the user to download the PDF.

      Looking at the docs this is what I did.

      In my web.xml, I added:

      <filter-name>Seam Servlet Filter</filter-name>
      <filter-class>
      org.jboss.seam.servlet.SeamServletFilter
      </filter-class>


      <filter-mapping>
      <filter-name>Seam Servlet Filter</filter-name>
      <url-pattern>*.pdf</url-pattern>
      </filter-mapping>


      <servlet-name>Document Store Servlet</servlet-name>
      <servlet-class>
      org.jboss.seam.pdf.DocumentStoreServlet
      </servlet-class>


      <servlet-mapping>
      <servlet-name>Document Store Servlet</servlet-name>
      <url-pattern>*.pdf</url-pattern>
      </servlet-mapping>

      In components.xml, I added:
      <pdf:documentStore useExtensions="true" />

      In my .xhtml page, I places a link as such:
      <s:link id="agent-pdf" view="/agent-pdf.xhtml">PDF</s:link>

      I created an agent-pdf.xhtml page as such:
      <p:document xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:s="http://jboss.com/products/seam/taglib"
      xmlns:p="http://jboss.com/products/seam/pdf"
      xmlns:h="http://java.sun.com/jsf/html">
      <f:facet name="header">
      <p:font size="12">
      <p:footer borderWidthTop="1" borderColorTop="blue" borderWidthBottom="0" alignment="center">Why Seam? [<p:pageNumber />]</p:footer>
      </p:font>
      </f:facet>
      <p:paragraph spacingAfter="200" />
      <p:font size="24"><p:paragraph spacingBefore="100" alignment="center">Ten Good Reasons To Use Seam</p:paragraph></p:font>
      <p:image alignment="center" value="#{agent.photo.data}" />
      <p:chapter number="1">
      <p:title>
      <p:font size="18"><p:paragraph>It's the quickest way to get "rich"</p:paragraph></p:font>
      </p:title>
      <p:paragraph alignment="justify" spacingBefore="5">AJAX fundamentally changes the interaction model of the web. The synchronous, coarse-grained requests used by traditional web clients let many server-side applications get away with minimal caching and no session-level concurrency. The "stateless" architecture is in many cases a viable solution. But not anymore! AJAX clients hit the server with many asynchronous, concurrent, fine-grained requests, which could easily bring your database to its knees. When state is held in memory between requests, it is highly vulnerable to concurrency-related bugs, since the Java EE platform provides no constructs for dealing with session-level concurrency.</p:paragraph>
      <p:paragraph alignment="justify" spacingBefore="5">Seam's totally unique concurrency model and state-management model was conceived and designed with AJAX in mind. </p:paragraph>
      <p:paragraph alignment="justify" spacingBefore="5">Seam 1.1 integrates open source JSF-based AJAX solutions like ICEfaces and Ajax4JSF with Seam's state and concurrency management engine. You can add AJAX to your applications with ease, without the need to learn JavaScript, and you will be protected from potential bugs and performance problems associated with the switch to AJAX. </p:paragraph>
      </p:chapter>
      <p:chapter number="2">
      <p:title>
      <p:font size="18"><p:paragraph>It's the easiest way to get started with EJB 3.0 </p:paragraph></p:font>
      </p:title>
      <p:paragraph alignment="justify" spacingBefore="5">EJB 3.0 is a great component model for transactional business components, the highlight being the brand new Java Persistence API (JPA). But Java web and application frameworks designed before the release of EJB 3.0 lack support for the new component model, leaving you to write your own integration code, and in many cases forcing you into the use of a layered architecture that may not be right for your application. </p:paragraph>
      <p:paragraph alignment="justify" spacingBefore="5">Seam was designed for use with EJB 3.0 and lets you use the new component model everywhere. Since any class in a Seam application can be an EJB component, there is no need to introduce extra unwanted layers just to keep your frameworks happy. And, of course, there is no need to write code to integrate EJB 3.0 with your web framework, since Seam already has it. </p:paragraph>
      <p:paragraph alignment="justify" spacingBefore="5">Note that you don't have to use EJB 3.0 to use Seam, and if you're developing in an environment that doesn't support EJB 3.0, Seam provides alternatives. </p:paragraph>
      </p:chapter>
      </p:document>

      The page doesn't throw an error but only shows a blank page. Anyway help would be greatly appreciated. Hopefully I'm on the right track.

      W

        • 1. Re: iText PDF not working with DocumentStore and SeamServlet
          Waseem Quraishi Newbie

          Actually, the page is throwing an error, here's the stacktrace:

          10:40:46,001 ERROR [ExceptionFilter] exception root cause
          java.lang.IllegalStateException: No active event context
          at org.jboss.seam.core.Manager.instance(Manager.java:248)
          at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:48)
          at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:82)
          at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
          at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
          at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
          at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
          at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
          at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
          at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
          at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:68)
          at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:149)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
          at java.lang.Thread.run(Thread.java:613)

          • 2. Re: iText PDF not working with DocumentStore and SeamServlet
            Waseem Quraishi Newbie

            That has to be an easy answer. Comon anyone...? Thanks.

            • 3. Re: iText PDF not working with DocumentStore and SeamServlet
              Norman Richards Master

              I don't see anything immediately out of place. Does the itext example work for you?

              • 4. Re: iText PDF not working with DocumentStore and SeamServlet
                Waseem Quraishi Newbie

                yes, the itext example works for me.

                • 5. Re: iText PDF not working with DocumentStore and SeamServlet
                  Waseem Quraishi Newbie

                  Woohooo...I got it working. For everyone else that's in this situation, in order to rectify the problem, I simply commented the following:


                  <!--


                  <filter-name>Seam Servlet Filter</filter-name>
                  <filter-class>
                  org.jboss.seam.servlet.SeamServletFilter
                  </filter-class>


                  <filter-mapping>
                  <filter-name>Seam Servlet Filter</filter-name>
                  <url-pattern>*.pdf</url-pattern>
                  </filter-mapping>

                  -->
                  <servlet-name>Document Store Servlet</servlet-name>
                  <servlet-class>
                  org.jboss.seam.pdf.DocumentStoreServlet
                  </servlet-class>


                  <servlet-mapping>
                  <servlet-name>Document Store Servlet</servlet-name>
                  <url-pattern>*.pdf</url-pattern>
                  </servlet-mapping>

                  I think it had to do with the two URL mappings both pointing to *.pdf. The one commented out was in the web.xml by default when creating an application using seam-gen.

                  So for everyone else, that starts of using inline PDF and then switches to using the link, you MUST comment out the code above.

                  • 6. Re: iText PDF not working with DocumentStore and SeamServlet
                    Sebastian Stenerdal Newbie

                    Thanks alot for sharing. This saved a whole bunch of hours for me.

                    When the documentation is wrong, it's always really helpful to find out as soon as possible. Usually, it's the last thing you question when things aren't working. :-)