Extended Scoping Module
Anyone ever wanted to have more than just three scopes in JSF, here is a possible solution. On top of Spring custom scopes, edoras provides some implementation of additional scopes, however, to use them, Spring has to be used as the managed bean container rather than the JSF bean facility. But this is a good decision anyway as Spring IoC Container offers a lot more features and simplicity of the JSF bean facility.
Currently the custom scopes can only be used with ICEfaces as they are based on the ICEfaces specific extended request scope extensively, but this will be changed in the future, as the core of this module will be integrated into Spring core 3.1 as a contribution.
Here is an overview of the different scopes offered by the edoras scoping module or the Spring IoC container:
(Listed from narrower to wider scopes, if possible)
- prototype (default Spring scope), every time a bean having this scope is requested through the container, a new instance is created and returned, it is never stored or shared within the container
- request (default Spring web scope), reflects the current request
- extRequest (additional edoras web scope), the same as the extended request scope in ICEfaces, lives between two GET requests, meaning, it does not persist across a refresh (F5), however, it persists across multiple postbacks like Ajax requests
- view (additional edoras web scope), the same as extRequest, but the scope is attached to the view-id, hence it persists across a refresh or even a redirect, as long as the same view is being rendered, even if the component tree was created from scratch, it is created on top of the window scope, so every tab or window running on the same session has its own state, if view scoped
- window (additional edoras web scope), basically the same as session, but this scope is attached to the browsers window or tab, isolating multiple tabs or windows from each other, having their own state actually since this scope persists as long as the same window or tab is used
- session (default Spring web scope), standard session scope, persisting its state in the http-session and is shared over multiple tabs or windows in the same browser
- conversation (additional edoras core scope), unlike every other scope, a conversation does not have a technical boundary and is rather created and ended upon business logic or annotation driven. It is usually used to reflect a business use case and a powerful tool to optimize the scoping of beans and entities, furthermore if used in conjunction with JPA, bounding the entity manager to conversation scope.
- process (additional edoras core scope), persists across a process instance (only available with the edoras workflow system), beans having process scope even persists between application restarts as they are persisted within the database.
- singleton / application (default Spring and JSF scope), a bean having this scope is only created once and shared within the application
The following conditions need to be met in order to use the current scoping module:
- You must use Spring (version 2.5.x or higher) as the bean container rather than the JSF bean facility
- You must use ICEfaces (version 1.7.2 or higher), as the window scope currently uses the extended request scope of ICEfaces
Here is a simple instruction on how to add the scoping module to your web application:
- Make sure the contextConfigLocation (context-parameter within web.xml) also includes Spring context files loaded from the classpath (e.g. classpath*:/META-INF/*-applicationContext.xml,/WEB-INF/applicationContext.xml), this will allow Spring to use the default configuration of the edoras scoping module shiped within the jars as a convention
- Make sure the com.icesoft.faces.concurrentDOMViews parameter is set to true
- Make sure ICEfaces uses the extended request scope, parameter com.icesoft.faces.standardRequestScope set to false
- Add the edoras-scopes jar to your classpath
- You should be all set!
Download the edoras-scopes-1.3 jars directly:
Download edoras-scopes-1.3.jar
Download edoras-scopes-1.3-src.jar