6 Replies Latest reply on May 10, 2007 4:15 PM by pmuir

    Access Seam Component from Servlet

    bengao

      Hi there,

      I try to use a Seam Component in a Servlet. Can I just simple put
      @In annotation in a servlet.

      Please advise

      Thanks,
      Ben

        • 1. Re: Access Seam Component from Servlet

          @In can only be used inside declared seam components (ones with @Name or explicit name in components.xml). You can't inject seam components into any object, only other seam components.

          • 2. Re: Access Seam Component from Servlet
            fernando_jmt

            You can use Components.getInstance("SeamComponentName");

            • 3. Re: Access Seam Component from Servlet
              gavin.king

              No, it is not a Seam component. You need to:

              (1) wrap the context filter around the servlet
              (2) use Component.getInstance()

              • 4. Re: Access Seam Component
                pdhaigh

                (1) wrap the context filter around the servlet

                Is it possible to access seam components without an HTTP request?

                e.g. in a background maintenance thread? (perhaps started with a servlet init-on-startup)

                • 5. Re: Access Seam Component from Servlet
                  christian.bauer

                  I don't think that is currently possibly. Although that is the same problem we have with webservice calls, and Shane has implemented something in CVS already for this. I didn't look at it so I'm clueless but you might want to check the examples Shane has been working on.

                  • 6. Re: Access Seam Component from Servlet
                    pmuir

                    Yes it is possible, it just depends on where the request originates. We currently have:

                    * JBPM
                    * EJB MDB (JMS works on 4.0.5, other JCA doesn't)
                    * EJB timers
                    * WS (in CVS)
                    * JSF (for completeness)

                    Otherwise, you *should* be able to apply the principle to another request - you just have to set up and clean up the Seam contexts yourself - this is obviously harder for stateful than stateless requests (you just have EVENT and APPLICATION scope for free, no session).

                    HTH