<< View previous version | view page history | view next version >>
Standard Scopes
The JSF 2.0 specification includes the standard scopes (request, session, and application) and also includes a new scope - View - which is maintained for each unique view in the session. Multiple Ajax-based requests can occur during the lifespan of a view. This scope eliminates the need for extended request scope as implemented in the ICEfaces 1.x vintage framework. ICEfaces 2.0 naturally inherits the new JSF 2.0 view scope.
Window Scope
The Window scope is an extended scope provided by the ICEfaces framework that acts much like View scope, but survives a page refresh. Under View scope a refresh results in the disposal of the current view and the creation of a new one, thus all view-scoped state is reset. ICEfaces provides a Window scope to help handle many use cases where the resetting of state on a page refresh may be undesirable. Under Window scope, if a view is disposed of, window-scoped state is held for a short configurable timeout period (typically a fraction of a second). If a GET occurs on the same view within the timeout duration, it is assumed to be a refresh of the current browser window and window-scoped state is maintained and associated with the new view. If the timeout expires, then the window-scoped state is disposed.
Using Window Scope
@CustomScoped
You can indicate that a managed bean should be in Window scope by marking it with the @CustomScope annotation and specifying an expression language binding to the "window" map:
package org.icefaces.demo; import javax.faces.bean.CustomScoped; import javax.faces.bean.ManagedBean; import java.io.Serializable; @ManagedBean @CustomScoped(value = "#{window}") public class MyWindowScopedBean implements Serializable { ...
faces-config.xml
A bean can also be marked for Window scope in a faces-config.xml file by specifying the custom map:
<managed-bean> <description> An example of a window-scoped bean </description> <managed-bean-name> myWindowScopedBean </managed-bean-name> <managed-bean-class> org.icefaces.demo.MyWindowScopedBean </managed-bean-class> <managed-bean-scope> #{window} </managed-bean-scope> </managed-bean>
Other Window Scope Annotations
There are other useful annotations related to the use of window-scoped beans.
Standard @PostConstruct and @PreDestroy Annotations
The standard @PostConstruct and @PreDestroy annotations that can be applied to managed beans in other scopes can also be applied to managed beans in Window scope:
package org.icefaces.demo; import javax.faces.bean.CustomScoped; import javax.faces.bean.ManagedBean; import java.io.Serializable; @ManagedBean @CustomScoped(value = "#{window}") public class MyWindowScopedBean implements Serializable { ... @PostConstruct public void setup(){ //code to execute after bean is constructed } @PreDestroy public void tearDown(){ //code to execute before bean is destroyed }
Custom ICEfaces Annotations
ICEfaces also provides other custom annotations which can be used in conjunction with windows-scoped beans.
The @AllWindowsClosed method annotation can be used on session scoped beans for helping to clean up resources when all the windows for a particular session have been closed.
The [@WindowDisposed] annotation is used for more efficient clean up of view-scoped beans.
More information is provided on these and other custom annotations in the Annotations section of the documentation.