Annotation Type ViewScoped
-
@Retention(RUNTIME) @Target(TYPE) @Inherited public @interface ViewScopedWhen this annotation, along with
ManagedBeanis found on a class, the runtime must act as if a<managed-bean-scope>view<managed-bean-scope>element was declared for the corresponding managed bean.If
ProjectStageis notProjectStage.Production, verify that the currentUIViewRootdoes not have itstransientproperty set totrue. If so, add aFacesMessagefor the currentviewIdto theFacesContextstating@ViewScopedbeans cannot work if the view is marked as transient. Also log aLevel.WARNINGmessage to the log. IfProjectStageisProjectStage.Production, do not do this verification.The bean must be stored in the map returned from
javax.faces.component.UIViewRoot.getViewMap(boolean).The runtime must ensure that any methods on the bean annotated with
PostConstructorPreDestroyare called when the scope begins and ends, respectively. Two circumstances can cause the scope to end.FacesContext.setViewRoot()is called with the newUIViewRootbeing different than the current one.The session, that happened to be active when the bean was created, expires. If no session existed when the bean was created, then this circumstance does not apply.
In the session expiration case, the runtime must ensure that
FacesContext.getCurrentInstance()returns a valid instance if it is called during the processing of the@PreDestroyannotated method. The set of methods onFacesContextthat are valid to call in this circumstance is identical to those documented as "valid to call this method during application startup or shutdown". On theExternalContextreturned from thatFacesContext, all of the methods documented as "valid to call this method during application startup or shutdown" are valid to call. In addition, the methodExternalContext.getSessionMap()is also valid to call.The annotations in this package may be deprecated in a future version of this specification because they duplicate functionality provided by other specifications included in JavaEE. When possible, the corresponding annotations from the appropriate Java EE specification should be used in preference to these annotations. In this case, the corresponding annotation is
javax.faces.view.ViewScoped. The functionality of this corresponding annotation is identical to this one, but it is implemented as a CDI custom scope.- Since:
- 2.0