2 Replies Latest reply on Oct 15, 2010 8:28 AM by Chun Shin

    FacesContext.getCurrentInstance() returns null in @Observer

    Chun Shin Newbie


      I have an @Observer method in an application scoped POJO bean and another conversation scoped SFSB like below:


      public class MyBean implements MyBeanInterface {
        public void methodA() {
          Events.instance().raiseAsynchronousEvent("eventToObserve", param1, param2);

      Another component listenerPojo:

      public class MyListenerPojo {
        public void process(String param1, String param2) {
          FacesMessage msg = someMessage;   
          doSomethingWithParams(param1, param2);
          FacesContext fc = FacesContext.getCurrentInstance();
          fc.addMessage(null, msg);

      The problem I'm facing here is that FacesContext.getCurrentInstance() returns null. Why is that? Is it because FacesContext is tied to the methodA request and the asynchronous method is running in a new thread? So, how can I access FacesContext?

      I'm just trying to implement something like what Leo had as an example in this post.

      Can someone please explain me?

      Thanks for your help in advance!