4 Replies Latest reply on May 29, 2008 11:06 PM by stephen

    Lazy Observers?

    stephen

      It seems not be possible to prevent creation of observers if an event is raised.


      It seems to me that this would be a good idea. Here's my use case:
      In my application there are several pieces of information that are shown only after an additional (2nd level) login (like sales prices).
      When that login is successful an event is thrown and several backing beans react on that, for example by showing additional columns, rows or options.


      Currently a lot of components may not even be used on the current page, but still they get created and have to include special code to ignore the event (because their context is not available).


      Is there a better solution?
      Should I file a Jira request?

        • 1. Re: Lazy Observers?
          pmuir

          So you want more control over the routing of events? How about using an intermediary that observes your macro event and calls finer grained ones as needed?

          • 2. Re: Lazy Observers?
            stephen

            Thanks a lot for your answer, Pete.



            So you want more control over the routing of events?

            Right. More or less a way to have create = false for event observers.



            How about using an intermediary ...

            Ah, ok, that's a workaround (though somewhat clumsy). It would look like this for my scenario:



            @Name("selectionEventMediator")
            @Scope(ScopeType.PAGE)
            public class SelectionEventMediator {
            
                @In(create = false, required = false)
                private ProductChartNavigation productChartNavigation;
            
                @In(create = false, required = false)
                private RegionNavigation regionNavigation;
            
                ...
                        a couple more
                ...
            
                @Observer(Selection.CHANGED_EVENT_NAME)
                public void handleSelectionChanged() {
                    if (productChartNavigation != null) {
                        productChartNavigation.handleSelectionChanged();
                    }
                    if (regionNavigation != null) {
                        regionNavigation.handleSelectionChanged();
                    }
                }
            }



            That said: Will it work if ProductChartNavigation et.al. are defined using @AutoCreate?
            Or will they be created in that case even though required = false for the @In declarations?


            • 3. Re: Lazy Observers?
              christian.bauer

              Stephen Friedrich wrote on May 29, 2008 21:01:


              Right. More or less a way to have create = false for event observers.



              @Observer(value="foo", create=false)

              • 4. Re: Lazy Observers?
                stephen

                Stupid me.


                Will read the fine manual one more time.


                Thanks for the answer.