Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* DelegatingVariableResolver.java
 
 {{IS_NOTE
 	Purpose:
 		
 	Description:
 		
 	History:
 		Thu Jun  1 13:53:53     2006, Created by andrewho
}}IS_NOTE
Copyright (C) 2006 Potix Corporation. All Rights Reserved.
{{IS_RIGHT
}}IS_RIGHT
*/
package org.zkoss.zkplus.spring;
import  javax.servlet.ServletContext;
import  org.springframework.beans.factory.NoSuchBeanDefinitionException;
import  org.springframework.context.ApplicationContext;
import  org.springframework.web.context.support.WebApplicationContextUtils;

DelegatingVariableResolver, a spring bean variable resolver.

It defines a variable called springContext to represent the instance of org.springframework.context.ApplicationContext. It also looks variables for beans defined in springContext.

Usage:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>

Author(s):
andrewho
public class DelegatingVariableResolver implements VariableResolver {
	protected ApplicationContext _ctx;
//	protected final Map _vars = new HashMap();
Get the spring application context.
	protected ApplicationContext getApplicationContext() {
		if ( != null)
			return ;
		 = SpringUtil.getApplicationContext();
//		_vars.put("springContext", _ctx);
		return ;
	}

Get the spring bean by the specified name.
	public Object resolveVariable(String name) {
		if ("springContext".equals(name)) {
		}
//		Object o = _vars.get(name);
//		if (o == null) {
			try {
				return getApplicationContext().getBean(name);
catch (NoSuchBeanDefinitionException ex) {
				return null;
			}
//			if (o != null)
//				_vars.put(name, o);
//		}
//		return o;
	}
New to GrepCode? Check out our FAQ X