Sun created JSF as a competition for ASP.net. Though the idea is good, yet, the Sun stuck with the aspect of configuration. So if I need the framework to manage any of my beans automatically, then I need to specify it in faces-config.xml. Lets say my bean is named ResultBean, then I will have to put it as follows
<
<managed-bean-name>Result
<managed-bean-class>org.me.ResultBean</managed-bean-class<
<managed-bean-scope>session</managed-bean-scope>
<managed-bean>
- Get a reference to FacesContext which essentially is ServletContex when compared to Servlet
- From FacesContext reference get current Application object
- From Application object get a reference to VariableResolver object
- Call resolveVariable method on it passing reference of the FacesContext and the name of the bean as string (not the class name)
FacesContext context = FacesContext.getCurrentInstance();
ResultBean bean = (ResultBean) context.getApplication().getVariableResolver().resolveVariable(context, "Result");