Frequently used annotations of JSF

Source: Internet
Author: User

@ManagedBean

Registers a class instance as a managed bean, and then puts it @...Scoped in the scope specified by one of the annotations. If no scope is specified, JSF places the bean in the request scope, and if no name is specified, JSF converts the first letter of the class name to lowercase to form a managed bean name, for example, if the class name is UserBean , JSF creates a managed bean named userBean . eagerand name properties are optional.

Note A Java class that implements the zero-parameter constructor must be used in conjunction.

@ManagedProperty
set a property for the managed bean. The comment must precede the declaration of the class member variable. nameproperty specifies the name of the attribute, by default, the name of the member variable. A value property is the value of an attribute, either a string or a JSF expression, such as #{...} .
@RequestScope
Store managed beans within the request scope.     
@SessionScoped
Store managed beans within the session scope.
@ApplicationScope
store managed beans within an application scope.
@ViewScope
Store managed beans within the view scope.
@NoneScope
specifies that the managed bean is not scoped. A non-scoped managed bean is useful when referenced by another bean.
@CustomScope

Store managed beans within a custom scope.

Custom scope refers to a map that can be accessed by the page creator. You can programmatically control the visibility and life cycle of a bean within a custom range. valueproperty points to a map.

@PostConstruct
after initialization of the resource injection
@PreDestory
when the servlet is out of service and frees the injected resources
@Resource
In
a class or variable to "inject resources" into the servlet container. When the container recognizes this annotation, it implements the re-injection of the annotated variable with the appropriate value before it obtains the service status. Using this notation, you do not have to use Jndi to find commands and manually declare resources in the config file Web. Xml. The server performs its tasks through the servlet's self-tuning. The name and type of the variable is determined automatically by the image mechanism, although you can use the parameters of the annotation to override this limitation. An injected resource can be a data source, a Java Information service destination file, or a scalar of environment settings.
@Resources
for a set of @resource annotations

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.