I needed to get request-scoped bean from view-scoped bean. It's not possible using @ManagedProperty annotation, so how to do that?
first create this method:
@SuppressWarnings("unchecked") public staticT getBean(final String beanName, final Class clazz) { ELContext elContext = FacesContext.getCurrentInstance().getELContext(); return (T) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, beanName); }
next just call:
getBean("beanName", BeanName.class);
Note: You need this dependency to make it work: http://javalibs.com/artifact/javax.el/javax.el-api
Made better & faster using https://www.yourkit.com/ Java Profiler