`

jsf bean

    博客分类:
  • jsf
阅读更多
我在jsf的自建adminBean保存了用户登录时的id
那我在别的bean中该怎么得到这个id值?
实在不知道该怎么得到了
分享到:
评论
1 楼 sech 2007-11-24  
搞定!
public static AdminBean getAdminBean() {
		return (AdminBean) getManagedBean(BeanNames.ADMIN_BEAN);
	}
/**
	 * Get managed bean based on the bean name.
	 * 
	 * @param beanName
	 *            the bean name
	 * @return the managed bean associated with the bean name
	 */
	public static Object getManagedBean(String beanName) {
		Object o = getValueExpression(getJsfEl(beanName)).getValue(
				FacesContext.getCurrentInstance().getELContext());
		return o;
	}

public static ValueExpression getValueExpression(String el) {
		return getApplication().getExpressionFactory().createValueExpression(
				FacesContext.getCurrentInstance().getELContext(), el,
				Object.class);
	}
private static Application getApplication() {
		ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder
				.getFactory(FactoryFinder.APPLICATION_FACTORY);
		return appFactory.getApplication();
	}

注:BeanNames.ADMIN_BEAN 为您要取的bean

相关推荐

Global site tag (gtag.js) - Google Analytics