Wednesday, December 28, 2011

Accessing another managed Bean


The Two method Suppose I want to access the login bean from welcome bean.
1) Using the Value Binding
FacesContext fc = FacesContext.getCurrentInstance();
LoginBean loginBean = (LoginBean)  fc.getApplication().createValueBinding("# {login}").getValue(fc);

2) Using the Variable Resolver
FacesContext fc = FacesContext.getCurrentInstance();
LoginBean loginBean = (LoginBean) fc.getApplication().getVariableResolver().resolveVariable(fc, "login");