About @model annotations in Java EE6

Source: Internet
Author: User

= = = @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.

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.