I read through CDI injections in JavaEE 7, in particular using @Qualifier and @Produces to introduce custom Data type in a bean.
I have the following code taken from the JBoss documentation at the end of the page.
@Qualifier @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) public @interface HttpParam { @Nonbinding public String value(); } import javax.enterprise.inject.Produces; import javax.enterprise.inject.spi.InjectionPoint; class HttpParams { @Produces @HttpParam("") String getParamValue(InjectionPoint ip) { ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value()); } }
And this qualifier can be used as follows:
@HttpParam("username") @Inject String username; @HttpParam("password") @Inject String password;
My question is:
What does the @Nonbinding annotation @Nonbinding ? and why is it needed?
If the method signature should always be like this @Nonbindng public String value(); . The reason I'm asking about this is a few examples, but they all have the same signature. This is valid:
public @interface HttpParam {
@Nonbinding public int value ();
}
- May I have several methods defined in the interface. That is, is it permissible or not?
public @interface HttpParam {
@Nonbinding public String value ();
@Nonbinding public int value1 ();
} thanks
source share