jsf検索Spring管理のbean


このツール類はJSF世界でSpring管理を検索するbeanを提供します。SpringでJSFコンポーネントを検索する方法も実現します。
package com.skysoft.rbac.dao;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.faces.el.ValueBinding;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
public final class SpringFacesUtil {
public SpringFacesUtil() {
}
/**
*  Spring   bean.
* @param beanname String
* @return Object
*/
public static Object findBean(String beanname) {
	ServletContext context = (ServletContext) FacesContext.getCurrentInstance().
	getExternalContext().getContext();
	ApplicationContext appctx = WebApplicationContextUtils.
	getRequiredWebApplicationContext(context);
	return appctx.getBean(beanname);
}
/**
*  JSF   bean.
* @param beanname String
* @return Object
*/
public static Object lookupBean(String beanname) {
	Object obj = getValueBinding(getJsfEl(beanname)).getValue(FacesContext.
	getCurrentInstance());
	return obj;
}
private static ValueBinding getValueBinding(String el) {
	return getApplication().createValueBinding(el);
}
private static Application getApplication() {
	ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder.
	getFactory(FactoryFinder.APPLICATION_FACTORY);
	//FactoryFinder.FACES_CONTEXT_FACTORY
	//FactoryFinder.RENDER_KIT_FACTORY
    	return appFactory.getApplication();
}
private static String getJsfEl(String value) {
	return "#{" + value + "}";
}
}