3 Replies Latest reply on May 21, 2008 3:11 PM by tomstrummer.tomstrummer.gmail.com

    Problem with Seam application context

    hypherion

      Hi there,


      I'm trying to get access to the seam context in my custom Servlet. I've followed the tutorial by adding the context-filter to the components.xml file.


      Yet I keep getting the No application context active problem when I call Component.getInstance(name). could someone check my config below and tell me what I am doing wrong ?


      It's probably something trivial but I can't seem to get it.


      my components.xml


      
      <?xml version="1.0" encoding="UTF-8"?>
      
      <components xmlns="http://jboss.com/products/seam/components"
      
        xmlns:core="http://jboss.com/products/seam/core"
      
        xmlns:framework="http://jboss.com/products/seam/framework"
      
        xmlns:web="http://jboss.com/products/seam/web"
      
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      
        xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd 
      
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd 
      
                       http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-1.2.xsd">
      
        
      
        <core:init jndi-pattern="belgacom-my1x07-front/#{ejbName}/local" debug="true"/>
      
      
        <core:manager conversation-timeout="120000"/>
      
        
      
        <web:redirect-filter url-pattern="*.seam"/>  
      
        
      
        <web:context-filter url-pattern="/results"/>
      
        
      
      </components>
      
      
      




      web.xml (the part that matters)


      
      <listener>
      
            <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
      
         </listener>
      
          
      
          <filter>
      
              <filter-name>Seam Filter</filter-name>
      
              <filter-class>org.jboss.seam.web.SeamFilter</filter-class>
      
          </filter>
      
      
          <filter-mapping>
      
              <filter-name>Seam Filter</filter-name>
      
              <url-pattern>/*</url-pattern>
      
          </filter-mapping>
      
      <servlet> 
      
            <servlet-name>ResultImage servlet</servlet-name>
      
            <servlet-class>be.belgacom.my1x07.front.web.util.GraphicResultsServlet</servlet-class>
      
         </servlet>
      
          
      
         <servlet-mapping>
      
            <servlet-name>ResultImage servlet</servlet-name>
      
            <url-pattern>/results</url-pattern>
      
         </servlet-mapping>
      
      




      a piece of xhtml calling the servlet


      
      <img src="/results?conversationId=#{conversation.id}&amp;view=overview&amp;result=${counter.index}" />
      
      



      Thx in advance.
      Verheire Kris.

        • 1. Re: Problem with Seam application context
          shane.bryzak

          It looks ok to me, however you might like to set a breakpoint in AbstractFilter.isMappedToCurrentRequestPath() to check whether the request is actually matching the URL pattern.

          • 2. Re: Problem with Seam application context
            hypherion

            Hi there,


            setting a breakpoint there solved my issue.
            I tried to access the seam context in my Servlet's init method.
            But this method is invoked before the seam context is provided.


            Moved the call to Component and all was well again.

            • 3. Re: Problem with Seam application context
              tomstrummer.tomstrummer.gmail.com

              It would be nice if this were documented in the Seam Documentation.    The section is only about a dozen lines and doesn't really explain how to use the context once that filter is added.  Luckily Google knows about the blog entry that shows how to use Context.getInstance, but it leaves out this detail. 


              Since I'm trying to access a (Application-scoped) service, it would have made more sense to retrieve it in the init method, and hold a reference to it as an instance field in my servlet.  That I can't do this is a little annoying, but my point is, it could be a little more clearly documented.


              Maybe I'll open a feature request.