2 Replies Latest reply on Jul 28, 2006 12:43 AM by recycle_bin

    Get ServletContext in Session Bean

    recycle_bin

      I would preload system data to ServletContext for later use during system up. Then i will get those data in the Session Bean (both stateful and stateless).

      I use following code to retrieve
      Context context = Contexts.getApplicationContext();

      But, context is NULL. Is there anything that i need to take care when i use getApplicationContext()? or are there other ways to achieve same goal?


      Thanks.

        • 1. Re: Get ServletContext in Session Bean

          How are you making this call? You'll only be able to lookup a Seam context after Seam has initialized and while you're within some web request.

          So calling this method via a startup servlet will probably fail. Calling this method via an EJB or MDB that is executed via a non-web request (ie executed directly via IIOP) will also probably fail.

          With few exceptions Seam only really works (has context) within the JSF lifecycle. It sounds like you may be trying to use it outside of this. Or you may simply have Seam misconfigured. I need more info please.

          • 2. Re: Get ServletContext in Session Bean
            recycle_bin

            Thank Cptnkirk. it works now when i call session bean through JSF. i made a mistake that i call such session bean in a servlet.