1. @ Model note solution usage
@ Model note:
Make the bean have a request-scoped cycle (take the @ dependent recognized by the proxy)
Give bean an EL name
Create a bean that asks for an example and assigns it a name, just like a class labeled with @ RequestScoped and @ Named, since the frequent combination of injection and solution groups is available in Web applications, CDI provides the inner-built annotation @ Model for use.
Example 1. @ Model example child
@ 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 the JSF View:
Example 2.
<H: inputText value = "# {sampleBean. value}"/>
If you want to access the bean through the EL name on the JSF page, you can add @ Dependent annotation to the class. No, any value set by JSF input will be invalid immediately. This is why CDI provides @ Model class type. It allows you to give bean a life name and set the bean's cycle to @ RequestScoped. If you actually access a bean On the JSF page during the @ dependent week and inject a different bean, you can use the getter method to save it to EL.
A stereotype is used to aggregate its injection solution. @ Model is a CDI built-in stereotype. Its definition is as follows:
Example 3.
@ Named
@ RequestScoped
@ Stereotype
@ Target ({TYPE, METHOD })
@ Retention (RUNTIME)
Public @ interface Model {}
@ Modelstereotype Note: This frequently used field should be used in web applications.