JSF如何获取backbean的值

来源:百度知道 编辑:UC知道 时间:2024/05/30 14:06:46
如题

你描述的不是很清楚,我把几种取值都说一下吧。
如你的bean为userBean,里面有username,userpas属性
前台取值:
直接拿来用就可以了。如:
<h:inputText value= "#{userBean.username} "/ >

后台取值:
你的后台处理中要有getUser(),setUser()方法,这样提交的时候会自动填充的。你在方法中直接用user.getUsername();就可以了

如果你想在任何页面或后台中取到整个bean的话,就用:
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding binding =
context.getApplication().createValueBinding( "#{userBean}");
User user = (User) binding.getValue(context);
其中user就是你个整个bean