= = = @Model The purpose of the annotation @Model annotation does the following things:
Make the bean have a request-scoped cycle range (replace the default @dependent) give the Bean an El name
Create a request scope and give a named Bean, like a class labeled @requestscoped and @named, since such annotation combinations frequently appear in Web applications, CDI provides built-in annotations @model easy to use.
@Model Example
@Model public class Samplebean {
private String value;
Public String GetValue () {return
value;
}
public string SetValue (string value) {
this.value = value;
}
}
Now this bean can be used in JSF view:
Typically, if you want to use the El name to access the bean in the JSF page, you may want to annotate the class with @dependent annotations. Otherwise, any values set through JSF input are immediately invalidated. This is why CDI provides the @model type; it lets you name the bean and set the bean's cycle to @requestscoped. If you do have access to a bean from a JSF page in the @dependent cycle, inject a different bean and leave it to El by the getter method.
A stereotype is an annotation used to aggregate other annotations. @Model is a CDI built-in stereotype, defined as follows:
@Named @RequestScoped @Stereotype @Target ({TYPE, method}) @Retention (RUNTIME) public @interface Model {}
@Modelstereotype annotations should be used frequently in Web applications.