1 Reply Latest reply on Nov 27, 2006 3:57 PM by Jeff Fry

    Need SeamServletFilter Example

    Jeff Fry Newbie

      I've been trying to access my seam components within my servlet without success. I keep getting null instances. Have I performed the steps correctly?

      1.Added SeamServletFilter to web.xml.

      <!-- propogate seam context to servlets -->
      <filter>
       <filter-name>Seam Servlet Filter</filter-name>
       <filter-class>org.jboss.seam.servlet.SeamServletFilter</filter-class>
      </filter>
      <filter-mapping>
       <filter-name>Seam Servlet Filter</filter-name>
       <url-pattern>*.serv</url-pattern>
      </filter-mapping>
      


      2. Explicitly passed conversation id to my servlet.
      <h:outputLink rendered="#{test.script!=null}" value="/TestSuiteAdmin/downloadTestScript.serv">
       <f:param name="conversationId" value="#{conversation.id}"/>
       <h:outputText value="download scipt"/>
      </h:outputLink>
      


      3. Restore the conversation and get my instance in my servlet.
       protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
       // TODO Auto-generated method stub
       super.doGet(req, resp);
      
       Manager mgr = Manager.instance();
       String conversation = req.getParameter("conversationId");
       mgr.restoreConversation(req.getParameterMap());
       Test test = (Test)Component.getInstance("test",false);
      
       resp.setContentType("text/plain");
      
       resp.getWriter().print(test.getScript());
       }
      


      "test" is always null.

      What am I doing wrong?

        • 1. Re: Need SeamServletFilter Example
          Jeff Fry Newbie

           

          @Override
           protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
           try {
          
           String configId = req.getParameter("id");
          
           EntityManagerFactory factory = (EntityManagerFactory)Naming.getInitialContext().lookup("java:/EntityManagerFactory");
           EntityManager em = factory.createEntityManager();
           Config config = (Config)em.find(Config.class, new Long(configId));
          
           resp.setContentType(config.getFileType());
          
           resp.getOutputStream().write(config.getFileData());
           }
           catch(Exception e){e.printStackTrace();}
           }