4 Replies Latest reply on May 12, 2008 9:11 PM by binnyg

    Quick Observer Questions

    darthmaul

      I am looking into the Seam component event model and @Observer, and I have two questions:



      • When I call events.raiseEvent("event", object), what is that second parameter?  What does it represent?  How do I access it in the method marked with @Observer (if possible)?




      • How do I test this interaction?  Is a SeamTest unit test (with setField/getField) sufficient?  Or must I use a full-fledged integration SeamTest?



      Thanks for any insight.

        • 1. Re: Quick Observer Questions
          jamathison

          The object that you pass in to raiseEvent will get passed in to your observer.


          Here is one of my event handlers:


          @Observer("deviceImported")
          public void importObserver (Device device) {
             int id = device.getId();
             // do stuff....
          }
          



          And the raiseEvent that invokes it:


             Device device = new Device();
             // do stuff to device, then fire event...
             Events.instance().raiseEvent ("deviceImported", device);
          

          • 2. Re: Quick Observer Questions
            darthmaul

            Thanks, Al. That makes sense.  Just to follow up, does the event get raised precisely when you call raiseEvent?  Or at the completion of the method where raiseEvent is called?


            Also, if you have tested your component, how do you do it?


            Thanks again.

            • 3. Re: Quick Observer Questions

              The event is raised directly. You'll see that if you set a breakpoint before the Events.instance()... and one in the observer method, and then just step.

              • 4. Re: Quick Observer Questions

                FYI. You can also raise Asynchronous events if you don't want your execution to wait until all listening code(@Observer) is executed.


                Events.instance().raiseAsynchronousEvent(type, parameters).