日期:2014-05-16 浏览次数:20441 次
@Component
public class BeanNamespacePostProcesser implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) throws BeansException {
String[] beanNames = beanFactory.getBeanDefinitionNames();
for(String beanName : beanNames){
if(beanName.indexOf('.') == -1)
continue;
else{
String[] terms = beanName.split("\\.");
Namespace space = Namespace.rootNamespace;
for(int i = 0;i<terms.length - 1; i++){
space = space.getOrCreateChild(terms[i]);
}
}
}
}
}
public class JSFELResolver extends SpringBeanFacesELResolver {
@Override
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
if (base == null) {
return resolveBase(elContext, property);
} else if (base instanceof Namespace) {
return resolveInNamespace(elContext, (Namespace) base, property);
}else {
return null;
}
}
private Object resolveInNamespace(ELContext elContext, Namespace base,
Object property) {
Object result = base.get((String) property);
elContext.setPropertyResolved(true);
return result;
}
private Object resolveBase(ELContext elContext, Object property) {
if(this.getWebApplicationContext(elContext).containsBean(property.toString())){
elContext.setPropertyResolved(true);
return this.getWebApplicationContext(elContext).getBean(property.toString());
}else{
Object result = Namespace.rootNamespace.get(property.toString());
if(result != null)
elContext.setPropertyResolved(true);
return result;
}
}
}
<el-resolver>el.JSFELResolver</el-resolver>