- java.lang.Object
-
- org.omnifaces.cdi.viewscope.ViewScopeManager
-
@ApplicationScoped public class ViewScopeManager extends Object
Manages view scoped bean creation and destroy. The creation is initiated byViewScopeContext
which is registered byViewScopeExtension
and the destroy is initiated byViewScopeEventListener
which is registered infaces-config.xml
.Depending on
ViewScoped.saveInViewState()
, this view scope manager will delegate the creation and destroy further to eitherViewScopeStorageInSession
orViewScopeStorageInViewState
which saves the concrete bean instances in respectively HTTP session or Faces view state.- Since:
- 1.6
- Author:
- Radu Creanga <rdcrng@gmail.com>, Bauke Scholtz
- See Also:
ViewScoped
,ViewScopeContext
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_ACTIVE_VIEW_SCOPES
Default value of maximum active view scopes in session.static String
PARAM_NAME_MAX_ACTIVE_VIEW_SCOPES
OmniFaces specific context parameter name of maximum active view scopes in session.static String
PARAM_NAME_MOJARRA_NUMBER_OF_VIEWS
Mojarra specific context parameter name of maximum number of logical views in session.static String
PARAM_NAME_MYFACES_NUMBER_OF_VIEWS
MyFaces specific context parameter name of maximum number of views in session.
-
Constructor Summary
Constructors Constructor Description ViewScopeManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> T
createBean(Contextual<T> type, CreationalContext<T> context)
Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetBean(Contextual, CreationalContext)
.<T> T
getBean(Contextual<T> type)
Returns the CDI view scoped managed bean from the current Faces view scope, ornull
if there is none.<T> T
getBean(Contextual<T> type, CreationalContext<T> context)
Returns the CDI view scoped managed bean from the current Faces view scope, and auto-creates one if it doesn't exist.static boolean
isUnloadRequest(FacesContext context)
Returnstrue
if the current request is triggered by an unload request.static boolean
isUnloadRequest(HttpServletRequest request)
Returnstrue
if the given request is triggered by an unload request.void
preDestroyView()
This method is invoked during view destroy byViewScopeEventListener
, in that case destroy all beans in current active view scope.
-
-
-
Field Detail
-
PARAM_NAME_MAX_ACTIVE_VIEW_SCOPES
public static final String PARAM_NAME_MAX_ACTIVE_VIEW_SCOPES
OmniFaces specific context parameter name of maximum active view scopes in session.- See Also:
- Constant Field Values
-
PARAM_NAME_MOJARRA_NUMBER_OF_VIEWS
public static final String PARAM_NAME_MOJARRA_NUMBER_OF_VIEWS
Mojarra specific context parameter name of maximum number of logical views in session.- See Also:
- Constant Field Values
-
PARAM_NAME_MYFACES_NUMBER_OF_VIEWS
public static final String PARAM_NAME_MYFACES_NUMBER_OF_VIEWS
MyFaces specific context parameter name of maximum number of views in session.- See Also:
- Constant Field Values
-
DEFAULT_MAX_ACTIVE_VIEW_SCOPES
public static final int DEFAULT_MAX_ACTIVE_VIEW_SCOPES
Default value of maximum active view scopes in session.- See Also:
- Constant Field Values
-
-
Method Detail
-
createBean
@Deprecated(since="4.5", forRemoval=true) public <T> T createBean(Contextual<T> type, CreationalContext<T> context)
Deprecated, for removal: This API element is subject to removal in a future version.Replaced bygetBean(Contextual, CreationalContext)
.Create and returns the CDI view scoped managed bean from the current Faces view scope.- Type Parameters:
T
- The expected return type.- Parameters:
type
- The contextual type of the CDI managed bean.context
- The CDI context to create the CDI managed bean in.- Returns:
- The created CDI view scoped managed bean from the current Faces view scope.
-
getBean
public <T> T getBean(Contextual<T> type, CreationalContext<T> context)
Returns the CDI view scoped managed bean from the current Faces view scope, and auto-creates one if it doesn't exist.- Type Parameters:
T
- The expected return type.- Parameters:
type
- The contextual type of the CDI managed bean.context
- The CDI context to create the CDI managed bean in.- Returns:
- The auto-created CDI view scoped managed bean from the current Faces view scope.
- Since:
- 4.5
-
getBean
public <T> T getBean(Contextual<T> type)
Returns the CDI view scoped managed bean from the current Faces view scope, ornull
if there is none.- Type Parameters:
T
- The expected return type.- Parameters:
type
- The contextual type of the CDI managed bean.- Returns:
- The CDI view scoped managed bean from the current Faces view scope, or
null
if there is none.
-
preDestroyView
public void preDestroyView()
This method is invoked during view destroy byViewScopeEventListener
, in that case destroy all beans in current active view scope.
-
isUnloadRequest
public static boolean isUnloadRequest(FacesContext context)
Returnstrue
if the current request is triggered by an unload request.- Parameters:
context
- The involved faces context.- Returns:
true
if the current request is triggered by an unload request.- Since:
- 2.2
-
isUnloadRequest
public static boolean isUnloadRequest(HttpServletRequest request)
Returnstrue
if the given request is triggered by an unload request.- Parameters:
request
- The involved request.- Returns:
true
if the given request is triggered by an unload request.- Since:
- 3.1
-
-