1 Reply Latest reply on Aug 22, 2012 10:06 AM by Martin Kouba

    Purpose of @Nonbinding and annotation-valued qualifiers

    Scott Stark Master

      Both the CDI 1.0 and 1.1 draft include this comment about Nonbinding:


      Array-valued or annotation-valued members of a qualifier type should be annotated @Nonbinding in a portable application.

      If an array-valued or annotation-valued member of a qualifier type is not annotated @Nonbinding , non-portable behavior



      What is the non-portable behavior one might see with annotation-valued qualifiers without @Nonbinding?


      I'm finding the usage of qualifiers with annotation member values difficult to deal with when using @Nonbinding as I posted in a previous thread. The canonical usecase of the HttpParam from "Chapter 4. Dependency injection and programmatic lookup" of the Weld docs I would argue should be written like this:


      public @interface HttpParam {
         public String value();
      class HttpParams
         @Produces @Nonbinding @HttpParam("")
         String getParamValue(InjectionPoint ip) {
            ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
            return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());


      So that only the producer method has the @Nonbinding annotation. This would allow an HttpParam user to differentiate both field injection as well as string events:


      class SomeHttpParamUser {
      @HttpParam("username") String username;
      @HttpParam("password") String password;
         public void setUsername(@Observes @HttpParam("username") String username) {...}
         public void setPassword(@Observes @HttpParam("password") String username) {...}


      Right now to get the same behavior one has to use an HttpParamNonbinding annotation that would include the @Nonbinding on the value on the fields and another HttpParam without the @Nonbinding on the event observer methods.