5 Replies Latest reply on Nov 20, 2009 7:40 AM by nickarls

    Custom qualifiers

    asookazian

      from ref doc:


      @Entity
      public class User {
         private @NotNull @Length(min=3, max=25) @Id String username;
         private @NotNull @Length(min=6, max=20) String password;
      
         public String getUsername() { return username; }
         public void setUsername(String username) { this.username = username; }
         public String setPassword(String password) { this.password = password; }
      }




      @Qualifier
      @Retention(RUNTIME)
      @Target({TYPE, METHOD, PARAMETER, FIELD})
      public @interface LoggedIn {}



      public class DocumentEditor {
      
         @Inject @LoggedIn User currentUser;
      
         public void save() {
           //do stuff
         }
      }



      So you're telling me that if I use that custom qualifier (@LoggedIn), then the CDI container will inject the currently logged in user?  So what would it inject if I did not use @LoggedIn?


      Why/how does that work?  So that's assuming that there is more than one User instance available to inject?


      And what scope is the injection occurring from (or is scoping a non-issue/irrelevant in CDI due to producer fields/methods)?


      [read the spec], I'm getting there...