JavaEE6 FAQs @ Model

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.