3 Replies Latest reply on Sep 6, 2010 5:58 AM by Pete Muir

    all Event are fired for qualified instance

    nimo stephan Master

      I have this:



      @SessionScoped @Named
      public class MyBean implements Serializable{
      ..
      
      @Inject @Read Event<Book> bookEvent;
      
      public void trigger(){
      
      ..
      bookEvent.select(new AnnotationLiteral<Read>(){}).fire(book);
      }
      
      public void onRead(@Observes @Read Book book) {
      
      log.info("Event-Consumer onRead is called !");
      
      }
      
      
      
      public void onWrite(@Observes Book book) {
      
      log.info("Event-Consumer onWrite is called !");
      
      }




      When trigger is called, then onRead AND onWrite is called.


      Why is onWrite also called?


      I have limited the event-consumer with @Read so it should not call onWrite.


      What is wrong?


        • 1. Re: all Event are fired for qualified instance
          Stuart Douglas Master

          This is the correct behavior, observer methods without qualifiers get notified for every event of that type. You probably want an @Write qualifier as well.


          • 2. Re: all Event are fired for qualified instance
            nimo stephan Master

            Is the correct behaviour reasonable?


            I told the event-producer exactly which events to be called:


            bookEvent.select(new AnnotationLiteral<Read>(){}).fire(book);



            I have narrowed (limited) the event consumer of the type Read, hence only event-consumer which observes the instances of type Read should be called.


            I do not say:


            bookEvent.fire(book);




            I also narrowed the type Book by injection:


            @Inject @Read Event<Book> bookEvent;




            I do not say:


            @Inject Event<Book> bookEvent;




            Or do I think wrong? Should I imagine it like this:


            class Book extends Paper {..}


            so book is a paper and when book is called, paper is also called?


            So


            @Inject @Book Event<Paper> bookEvent;



            with producer


            bookEvent.select(new AnnotationLiteral<Book>(){}).fire(book);



            calls all events of instances of books which are types of book and inheritly paper.





            • 3. Re: all Event are fired for qualified instance
              Pete Muir Master

              This is the correct behavior, observer methods without qualifiers get notified for every event of that type. You probably want an @Write qualifier as well.

              That's not quite right - an observer method must have all the event qualifiers. There was a bug in Weld that caused this to not work right - can you test with Weld 1.1.0.Beta1 please?