public class DelegatingNavigationHandlerProxy extends NavigationHandler
Configure this handler proxy in your faces-config.xml
file
as follows:
<application> ... <navigation-handler> org.springframework.web.jsf.DelegatingNavigationHandlerProxy </navigation-handler> ... </application>By default, the Spring ApplicationContext will be searched for the NavigationHandler under the bean name "jsfNavigationHandler". In the simplest case, this is a plain Spring bean definition like the following. However, all of Spring's bean configuration power can be applied to such a bean, in particular all flavors of dependency injection.
<bean name="jsfNavigationHandler" class="mypackage.MyNavigationHandler"> <property name="myProperty" ref="myOtherBean"/> </bean>The target NavigationHandler bean will typically extend the standard JSF NavigationHandler class. However, note that decorating the original NavigationHandler (the JSF provider's default handler) is not supported in such a scenario, since we can't inject the original handler in standard JSF style (that is, as constructor argument).
For decorating the original NavigationHandler, make sure that your target bean extends Spring's DecoratingNavigationHandler class. This allows to pass in the original handler as method argument, which this proxy automatically detects. Note that a DecoratingNavigationHandler subclass will still work as standard JSF NavigationHandler as well!
This proxy may be subclassed to change the bean name used to search for the
navigation handler, change the strategy used to obtain the target handler,
or change the strategy used to access the ApplicationContext (normally obtained
via FacesContextUtils.getWebApplicationContext(FacesContext)
).
DecoratingNavigationHandler
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_TARGET_BEAN_NAME
Default name of the target bean in the Spring application context:
"jsfNavigationHandler"
|
Constructor and Description |
---|
DelegatingNavigationHandlerProxy()
Create a new DelegatingNavigationHandlerProxy.
|
DelegatingNavigationHandlerProxy(NavigationHandler originalNavigationHandler)
Create a new DelegatingNavigationHandlerProxy.
|
Modifier and Type | Method and Description |
---|---|
protected BeanFactory |
getBeanFactory(FacesContext facesContext)
Retrieve the Spring BeanFactory to delegate bean name resolution to.
|
protected NavigationHandler |
getDelegate(FacesContext facesContext)
Return the target NavigationHandler to delegate to.
|
protected java.lang.String |
getTargetBeanName(FacesContext facesContext)
Return the name of the target NavigationHandler bean in the BeanFactory.
|
protected WebApplicationContext |
getWebApplicationContext(FacesContext facesContext)
Retrieve the web application context to delegate bean name resolution to.
|
void |
handleNavigation(FacesContext facesContext,
java.lang.String fromAction,
java.lang.String outcome)
Handle the navigation request implied by the specified parameters,
through delegating to the target bean in the Spring application context.
|
handleNavigation
public static final java.lang.String DEFAULT_TARGET_BEAN_NAME
public DelegatingNavigationHandlerProxy()
public DelegatingNavigationHandlerProxy(NavigationHandler originalNavigationHandler)
originalNavigationHandler
- the original NavigationHandlerpublic void handleNavigation(FacesContext facesContext, java.lang.String fromAction, java.lang.String outcome)
The target bean needs to extend the JSF NavigationHandler class.
If it extends Spring's DecoratingNavigationHandler, the overloaded
handleNavigation
method with the original NavigationHandler
as argument will be used. Else, the standard handleNavigation
method will be called.
handleNavigation
in class NavigationHandler
protected NavigationHandler getDelegate(FacesContext facesContext)
By default, a bean with the name "jsfNavigationHandler" is obtained from the Spring root WebApplicationContext, for every invocation.
facesContext
- the current JSF contextgetTargetBeanName(javax.faces.context.FacesContext)
,
getBeanFactory(javax.faces.context.FacesContext)
protected java.lang.String getTargetBeanName(FacesContext facesContext)
facesContext
- the current JSF contextprotected BeanFactory getBeanFactory(FacesContext facesContext)
Default implementation delegates to getWebApplicationContext
.
Can be overridden to provide an arbitrary BeanFactory reference to resolve
against; usually, this will be a full Spring ApplicationContext.
facesContext
- the current JSF contextnull
)getWebApplicationContext(javax.faces.context.FacesContext)
protected WebApplicationContext getWebApplicationContext(FacesContext facesContext)
Default implementation delegates to FacesContextUtils.
facesContext
- the current JSF contextnull
)FacesContextUtils.getRequiredWebApplicationContext(javax.faces.context.FacesContext)