2 Replies Latest reply on May 3, 2009 6:23 PM by Naresh Bhatia

    raiseEvent() auto-creates observer

    Naresh Bhatia Newbie

      I have a component that raises a accountSelected event:


      public class SelectedAccountManager {
          ...
          public void setSelectedAccount(Account selectedAccount) {
              this.selectedAccount = selectedAccount;
              Events.instance().raiseEvent("accountSelected");
          }
      }
      



      An observer listens for this event:


      public class OrderListController implements Serializable {
          @Observer("accountSelected")
          @Factory("orders")
          public void findOrders() {
              ...
          }
      }
      



      What I am seeing is that when the event is raised, the observer (in this case OrderListController) is created if it does not exist already. Is this the expected behavior? I would like the observer to listen to the event only if it exists already. In my use case, it does not make sense to foribly create the observer just to listen to the event. Is that possible at all?


      Thanks.
      Naresh