Java Reference
In-Depth Information
@Named
@Stereotype
@Target( { TYPE, METHOD, FIELD })
@Retention(RUNTIME)
public @interface CurrentUser {}
With this new annotation, you've consolidated
@SessionScoped
,
@Authenticated-User
, and
@Named
down to
@CurrentUser
. You can see this
annotation in action in the simplified code for the
CurrentUserBean
:
@Named @SessionScoped
public class CurrentUserBean implements Serializable {
@Produces
@CurrentUser
public User getCurrentUser() {
...
}
}
There are some ground rules for defining stereotypes. Stereotypes can encapsulate the fol-
lowing CDI annotations:
• Scope
• Interceptor bindings
• Named annotation for JSF integration
• Alternative annotation
You can't include other annotations such as those from JPA or EJB within a stereotype. You
also can't include
@Produces
and other lifecycle annotations within a stereotype.
CDI ships with a built-in stereotype,
@Model
, for beans that are intended for the model
component of the model-view-controller pattern. The
@Model
annotation is defined as fol-
lows:
@Named
@RequestScoped
@Documented
@Stereotype
@Target(value = {ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Model {}