1 16 17 package org.springframework.web.jsf; 18 19 import javax.faces.application.NavigationHandler; 20 import javax.faces.context.FacesContext; 21 22 import org.springframework.beans.factory.BeanFactory; 23 import org.springframework.web.context.WebApplicationContext; 24 25 73 public class DelegatingNavigationHandlerProxy extends NavigationHandler { 74 75 79 public final static String DEFAULT_TARGET_BEAN_NAME = "jsfNavigationHandler"; 80 81 private NavigationHandler originalNavigationHandler; 82 83 84 87 public DelegatingNavigationHandlerProxy() { 88 } 89 90 94 public DelegatingNavigationHandlerProxy(NavigationHandler originalNavigationHandler) { 95 this.originalNavigationHandler = originalNavigationHandler; 96 } 97 98 99 108 public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) { 109 NavigationHandler handler = getDelegate(facesContext); 110 if (handler instanceof DecoratingNavigationHandler) { 111 ((DecoratingNavigationHandler) handler).handleNavigation( 112 facesContext, fromAction, outcome, this.originalNavigationHandler); 113 } 114 else { 115 handler.handleNavigation(facesContext, fromAction, outcome); 116 } 117 } 118 119 128 protected NavigationHandler getDelegate(FacesContext facesContext) { 129 String targetBeanName = getTargetBeanName(facesContext); 130 return (NavigationHandler) getBeanFactory(facesContext).getBean(targetBeanName, NavigationHandler.class); 131 } 132 133 139 protected String getTargetBeanName(FacesContext facesContext) { 140 return DEFAULT_TARGET_BEAN_NAME; 141 } 142 143 152 protected BeanFactory getBeanFactory(FacesContext facesContext) { 153 return getWebApplicationContext(facesContext); 154 } 155 156 163 protected WebApplicationContext getWebApplicationContext(FacesContext facesContext) { 164 return FacesContextUtils.getRequiredWebApplicationContext(facesContext); 165 } 166 167 } 168 | Popular Tags |