Posts

Showing posts from March, 2013

JSF2 View Scope with Spring Core

Working with Spring and JSF2 I encountered the need to use something like a ViewScope bean. The Spring Framework support the following scopes bean scopes : singleton prototype request session globalSession Adding a new scope is quite simple using Spring. To add the View Scope in the Spring IoC container it is necessary to create a custom scope which implements the org.springframework.beans.factory.config.Scope interface and register it with the Spring Custom Scope Configurer. ViewScope implementation package eu.ac.tutorial.spring.scope; import java.util.Map; import javax.faces.context.FacesContext; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.Scope; public class ViewScope implements Scope {     @Override     public Object get(String name, ObjectFactory<?> objectFactory) {         if (FacesContext.getCurrentInstance().getViewRoot() != null) {             Map<String, Object> viewMap = FacesContext.getC