Java Reference
In-Depth Information
• Request ( @RequestScoped ): Request scope persists during a single HTTP re-
quest in a web application.
• None ( @NoneScoped ): Indicates a scope is not defined for the application.
• Custom ( @CustomScoped ): A user-defined, nonstandard scope. Its value must
be configured as a java.util.Map . Custom scopes are used infrequently.
You may want to use @NoneScoped when a managed bean references another managed
bean. The second bean should not be in a scope ( @NoneScoped ) if it is supposed to be
created only when it is referenced. If you define a bean as @NoneScoped , the bean is
instantiated anew each time it is referenced, so it does not get saved in any scope.
If your managed bean is referenced by the binding attribute of a component tag, you
should define the bean with a request scope. If you placed the bean in session or applic-
ation scope instead, the bean would need to take precautions to ensure thread safety, be-
cause javax.faces.component.UIComponent instances each depend on running
inside of a single thread.
If you are configuring a bean that allows attributes to be associated with the view, you can
use the view scope. The attributes persist until the user has navigated to the next view.
Eager Application-Scoped Beans
Managed beans are lazily instantiated. That is, that they are instantiated when a request is
made from the application.
To force an application-scoped bean to be instantiated and placed in the application scope
as soon as the application is started and before any request is made, the eager attribute
of the managed bean should be set to true as shown in the following example:
@ManagedBean(eager=true)
@ApplicationScoped
Application Configuration Resource File
JavaServer Faces technology provides a portable configuration format (as an XML docu-
ment) for configuring application resources. One or more XML documents, called applic-
ation configuration resource files , may use this format to register and configure objects
and resources, and to define navigation rules for applications. An application configura-
tion resource file is usually named faces-config.xml .
You need an application configuration resource file in the following cases:
Search WWH ::




Custom Search