7 Replies Latest reply on Dec 11, 2006 7:13 AM by cavani

    Component-driven events scope

    cavani

      I could not figure out from cap. 4 of docs if component-driven events are scoped or not.

      In doc (http://docs.jboss.com/seam/1.1BETA2/reference/en/html/events.html#d0e3261)


      You might wonder why I've not mentioned anything about event objects in this discussion. In Seam, there is no need for an event object to propagate state between event producer and listener. All state is held in the Seam contexts, and is shared between components.


      What happens when I have two components (both) on two different long conversations, first component rise an event that second "observe" (multiwindow, same forms, different data) and the first component of some conversation rise the event? both "seconds" will catch it or just the one in same long conversation?

      I think that I can almost approach conversation-scoped behavior observing "org.jboss.seam.postSetVariable." contextual events and outjecting simple object with some and this name will be my "event", right?

      Thanks,[/url]

        • 1. Re: Component-driven events scope
          gavin.king

          Events are processed in the scope of the conversation that raised them (except for async events).

          Anyway, the docs are outofdate, the latest releases do actually support arbitrary event objects.

          • 2. Re: Component-driven events scope
            cavani

            nice, very nice... now, my code can be much more loosely and pretty...

            thanks a lot,

            • 3. Re: Component-driven events scope
              cavani

              I realize now that I misundestood the concept of this kind of event.

              Originally, my idea was that I should create Components in one conversation context and a raised event just reached this created components that observe it.

              But, this doesn't work that way!

              Reading the Seam code (this help a lot!!), I realize that any component that observe the same event will be invoked, and created in same conversation when there isn't one.

              Any way to raise an event observed by many components, but that afects only sort of created components in same conversation?

              Thanks,

              • 4. Re: Component-driven events scope
                cavani

                I try this and it works good!

                I alter Events from Seam Core to:

                 private void eventProcessing(boolean create, String type, Object... parameters)
                 {
                 log.debug("Processing event:" + type);
                 List<MethodBinding> list = listeners.get(type);
                 if (list!=null)
                 {
                 for (MethodBinding listener: list )
                 {
                 listener.invoke(parameters);
                 }
                 }
                 List<Init.ObserverMethod> observers = Init.instance().getObservers(type);
                 if (observers!=null)
                 {
                 for (ObserverMethod observer: observers)
                 {
                 Object listener = Component.getInstance( observer.component.getName(), create );
                
                 if (listener == null)
                 continue;
                
                 observer.component.callComponentMethod(listener, observer.method, parameters);
                 }
                 }
                 }
                
                 public void raiseEvent(String type, Object... parameters)
                 {
                 eventProcessing(true, type, parameters);
                 }
                
                 public void sendEvent(String type, Object... parameters)
                 {
                 eventProcessing(false, type, parameters);
                 }
                


                Gavin, any chances to have this or something like?

                Thanks,

                • 5. Re: Component-driven events scope
                  gavin.king

                  Add a feature request to JIRA, sounds like a good idea.

                  • 6. Re: Component-driven events scope
                    cavani
                    • 7. Re: Component-driven events scope
                      cavani

                      I want suggest a second approach for the same feature:

                      @Observer(String[] value, boolean create)

                      Where the "boolean create" indicate if that component should be create when it not exists.

                      I dig a little on Seam code and conclude that this is very easy to do. This information could be setted on Init.ObserverMethod and Event.raiseEvent() could be changed to consider that.


                      This is less power than previous approach but is simple too.