I am reading through the CDI
injections in JavaEE 7 particularly using @Qualifier
and @Produces
to inject a custom Data type
into a bean.
I have the following code taken from JBoss documentation towards ends 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 could be used in the following way:
@HttpParam("username") @Inject String username;
@HttpParam("password") @Inject String password;
My question is :
what does
@Nonbinding
annotation mean? and why is it needed?Should the method signature should always be like this
@Nonbindng public String value();
. The reason I ask this is I have seen several different examples but they all have the same signature. That is the following allowed:
public @interface HttpParam { @Nonbinding public int value(); }
- can I have more than one method defined in the interface. That is, is the following allowed or not?
public @interface HttpParam { @Nonbinding public String value(); @Nonbinding public int value1(); }
Thanks