Idea

The idea of Simple JSF FlowScope is, as the name indicates, simple.

All the beans that are referenced by JSF in the screens, for storing input, showing data, or executing logic or looked up by a Variable resolver . In JSF 1.2, the concept is a bit broader and there we have a EL resolver that is responsible for resolving the dynamic patrs of the screen.

The Spring Framework has already resolvers that tries to find the requested bean not only in the managed bean facility of JSF but also in the beans defined in the Spring application context. And with Spring, we are able to define custom scopes , a possibility introduced in Spring 2. With a custom scope, we can define how and where beans should be searched when the Beanfactory of Spring needs to resolve a reference to a bean.

So the trick used in Simple JSF FlowScope is to define a custom scope, that stores the beans at the servlet session but that we keep track of are requests to these types of beans. When the scope gets a request for a certain bean, it logs the name in a list maintained on request scope (so every post/reply cycle the list is emptied) and application scope (list contains thus the name of every bean ever resquested in our custom scope). The hard work, like resolving and instantiating the bean we hand it over to the SessionScope of Spring. So our beans are stored on session and thus kept for more then one post/reply cycle .

The last bit is done by a JSF PhaseListener , the removal of the beans from the session if they are no longer referenced in the request. The PhaseListener is sheduled to do his work after each renderResponse phase , the last phase in the JSF Lifecycle. It asks for the 2 lists maintained by the custom scope. It removes from the session all the beans available in the application scope list which are not found in the request scope list.

Simple as that.