I have view scope search and edit beans which are created by:
javax.faces.bean.ManagedBean
javax.faces.bean.ViewScoped
When the user makes search and view the search results, he select a result and open it in new window and after the saving changes I want to update the results in search bean, so when I try to get the search bean using any of the following methods:
public static <T> T getBean(String beanName) {
FacesContext context = FacesContext.getCurrentInstance();
return (T) context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class);
}
public static <T> T getViewScopeBean(String beanName){
Map<String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();
return (T) viewMap.get(beanName);
}
it returns null and can't find the search bean for the second method, and for the first method it creates a new instance of the search bean (although the search page is still opened), when I printed all the values in the map it doesn't contain the search bean. How can I get the search bean?