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.springframework.util.Assert; 24 import org.springframework.web.context.WebApplicationContext; 25 26 51 public class WebApplicationContextVariableResolver extends VariableResolver { 52 53 56 public static final String WEB_APPLICATION_CONTEXT_VARIABLE_NAME = "webApplicationContext"; 57 58 59 protected final VariableResolver originalVariableResolver; 60 61 62 70 public WebApplicationContextVariableResolver(VariableResolver originalVariableResolver) { 71 Assert.notNull(originalVariableResolver, "Original JSF VariableResolver must not be null"); 72 this.originalVariableResolver = originalVariableResolver; 73 } 74 75 79 protected final VariableResolver getOriginalVariableResolver() { 80 return originalVariableResolver; 81 } 82 83 84 90 public Object resolveVariable(FacesContext context, String name) throws EvaluationException { 91 Object value = null; 92 if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(name)) { 93 value = getWebApplicationContext(context); 94 } 95 if (value == null) { 96 value = getOriginalVariableResolver().resolveVariable(context, name); 97 } 98 return value; 99 } 100 101 109 protected WebApplicationContext getWebApplicationContext(FacesContext facesContext) { 110 return FacesContextUtils.getWebApplicationContext(facesContext); 111 } 112 113 } 114 | Popular Tags |