1 16 17 package org.springframework.web.jsf; 18 19 import javax.faces.context.FacesContext; 20 import javax.faces.el.EvaluationException; 21 import javax.faces.el.VariableResolver; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import org.springframework.beans.factory.BeanFactory; 27 import org.springframework.util.Assert; 28 import org.springframework.web.context.WebApplicationContext; 29 30 70 public class DelegatingVariableResolver extends VariableResolver { 71 72 73 protected final Log logger = LogFactory.getLog(getClass()); 74 75 protected final VariableResolver originalVariableResolver; 76 77 78 85 public DelegatingVariableResolver(VariableResolver originalVariableResolver) { 86 Assert.notNull(originalVariableResolver, "Original JSF VariableResolver must not be null"); 87 this.originalVariableResolver = originalVariableResolver; 88 } 89 90 94 protected final VariableResolver getOriginalVariableResolver() { 95 return originalVariableResolver; 96 } 97 98 99 103 public Object resolveVariable(FacesContext facesContext, String name) throws EvaluationException { 104 if (logger.isDebugEnabled()) { 106 logger.debug("Attempting to resolve variable '" + name + "' in via original VariableResolver"); 107 } 108 Object originalResult = getOriginalVariableResolver().resolveVariable(facesContext, name); 109 if (originalResult != null) { 110 return originalResult; 111 } 112 113 if (logger.isDebugEnabled()) { 115 logger.debug("Attempting to resolve variable '" + name + "' in root WebApplicationContext"); 116 } 117 BeanFactory bf = getBeanFactory(facesContext); 118 if (bf.containsBean(name)) { 119 if (logger.isDebugEnabled()) { 120 logger.debug("Successfully resolved variable '" + name + "' in root WebApplicationContext"); 121 } 122 return bf.getBean(name); 123 } 124 125 if (logger.isDebugEnabled()) { 126 logger.debug("Could not resolve variable '" + name + "'"); 127 } 128 return null; 129 } 130 131 140 protected BeanFactory getBeanFactory(FacesContext facesContext) { 141 return getWebApplicationContext(facesContext); 142 } 143 144 151 protected WebApplicationContext getWebApplicationContext(FacesContext facesContext) { 152 return FacesContextUtils.getRequiredWebApplicationContext(facesContext); 153 } 154 155 } 156 | Popular Tags |