论坛首页 入门技术论坛

jsf bean

浏览 1879 次
锁定老帖子 主题:jsf bean
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-11-23  
我在jsf的自建adminBean保存了用户登录时的id
那我在别的bean中该怎么得到这个id值?
实在不知道该怎么得到了
   发表时间: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
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics