4 Replies Latest reply on Oct 22, 2009 2:35 AM by gavin.king

    Events on Tomcat

    fabiowg

      Hi again,


      I'm testing Weld's events feature on tomcat (6.0.20) and I was wondering if what I saw was the expected behavior.


      Action.java



      @Named
      @SessionScoped
      public class Action implements Serializable {
      
              @Inject
              BeanManagerImpl manager;
      
              public void mantain() {
                      manager.fireEvent(new Object(), new SpecialQualifier() {});
              }
      
              public void onEvent(@Observes Object event) {
                      System.out.println("onEvent");
                      System.out.println(event);
              }
      
              public void onSpecialEvent(@Observes @Special Object event) {
                      System.out.println("onSpecialEvent");
                      System.out.println(event);
              }
      }



      When the mantain method is invoked I expect onEvent and onSpecialEvent to be triggered, but I get only the onSpecialEvent printed to the console.
      Is this a bug or this feature is not yet completely implemented?

        • 1. Re: Events on Tomcat
          gavin.king

          Sounds like a possible bug to me. Are you sure that @Special is annotated @Qualifier, and that SpecialQualifier implements Special?


          If so, please submit this test code to JIRA,


          Why are you using BeanManager directly, instead of @Inject Event<Object> objectEvent?

          • 2. Re: Events on Tomcat
            fabiowg
            Why are you using BeanManager directly, instead of @Inject Event<Object> objectEvent?




            Well, I'm just testing the weld features, and I was trying something similar to the first example of the PFD2:



            public void login() {
                final User user = ...;
                manager.fireEvent( new LoggedInEvent(user), new RoleQualifier() { public String value() { return user.getRole(); } );
            }



            However, trying what you've said:



            @Inject Event<Object> objectEvent;
            
            public void mantain() {
                objectEvent.select(new SpecialQualifier() {}).fire(new Object());
            }




            And it does work! Is this something that should be corrected in the documentation, though?

            • 3. Re: Events on Tomcat
              fabiowg

              (Hehe, just tried this:



              manager.fireEvent(new Object(), new DefaultLiteral(), new SpecialQualifier() {});




              and it works too :-D)

              • 4. Re: Events on Tomcat
                gavin.king

                Well, that definitely looks like a bug. @Default has nothing to do with observer methods. Please report this in JIRA. Thanks.