3 Replies Latest reply on Dec 6, 2008 5:07 AM by Matt Drees

    Use Seam Components from a non-seam class?

    Matt Davis Newbie

      Is it possible to use Seam from a non-seam class? I have a java class that is being instantiated and managed by another process.  I have no control over how that object is instantiated, so it isn't using Component.getInstance or any of that.


      Once I'm in a method of that class, how do I make a call to a Seam component so that I can use SMPC and other seam features? I've tried just calling Component.getInstance(myClass) and calling the methods directly from there... but it tells me that there is no Application Context active.


      I'd like to have the rest of my app using Seam, but I have to access the app through this one rogue class that can't be managed by seam.


      I've seen posts like this:
      http://www.seamframework.org/Community/CanYouYseSeamForNonwebApps
      Where it talks about doing all of this Lifecycle.beginRequest and Lifecycle.beginCall stuff... But it seems kind of vague and I'm not sure if Seam will actually work correctly if used that way.


      How do I go about this? Is there an approved way to pull this off?

        • 1. Re: Use Seam Components from a non-seam class?
          Matt Drees Master

          Does this other process occur in the context of a servlet request?  If so, you could use the Seam context filter (it's in the docs somewhere), and map the filter to that request's url.


          If not, you'll probably want to use Lifecycle.beginCall() before your seam-aware code and Lifecycle.endCall() afterwards.

          • 2. Re: Use Seam Components from a non-seam class?
            Matt Davis Newbie

            I am not in a servlet context. I can wrap the code inside each method with Livecycle.beginCall and Lifecycle.endCall.


            There are other cases where I will call a session bean outside the context of a servlet request. I would like to hit that session bean already inside the seam context so I can have injection active and whatnot.


            Any suggestions on making my second requirement work?



            Just FYI, I'm using Flex and LiveCycle Data Services. LCDS has an assembler class that is a java class. It is the single access point for the whole java application while doing data manipulation.


            However, I will also be calling session beans directly from flex on a channel that does not have a servlet context.   I don't know how I could wrap that request in the Lifecycle calls, unless I wrap every method I access in those calls.


            I assume those Lifecycle calls always behave like a real call and I'd never notice the difference... do they?

            • 3. Re: Use Seam Components from a non-seam class?
              Matt Drees Master

              Matt Davis wrote on Dec 05, 2008 23:31:


              I am not in a servlet context. I can wrap the code inside each method with Livecycle.beginCall and Lifecycle.endCall.

              There are other cases where I will call a session bean outside the context of a servlet request. I would like to hit that session bean already inside the seam context so I can have injection active and whatnot.

              Any suggestions on making my second requirement work?


              I'm afraid I don't understand what you're saying.  What's the difference between not [being] in a servlet context and being outside the context of a servlet request?




              Just FYI, I'm using Flex and LiveCycle Data Services. LCDS has an assembler class that is a java class. It is the single access point for the whole java application while doing data manipulation.

              However, I will also be calling session beans directly from flex on a channel that does not have a servlet context.   I don't know how I could wrap that request in the Lifecycle calls, unless I wrap every method I access in those calls.


              Well, if you're calling session beans, then I don't think you'd need to manually call Lifecycle.beginCall(), because the SeamInterceptor attached to that session bean will do this for you.  (Though, I haven't really ever tested this; I'm just inferring this from reading through source code.)


              Do you ever need to access Seam outside a session bean? 





              I assume those Lifecycle calls always behave like a real call and I'd never notice the difference... do they?


              Not 100% what you mean by a real call.  If you mean a normal Seam JSF request, then it's not quite the same. For instance, calling Lifecyle.beginCall() won't give you access to the user's httpSession, so the session context is kinda useless. But it's definitely a legitimate way to set up the seam contexts, if that's what you're asking.