Get JSF managed bean by name in any Servlet related class

前端 未结 6 639
难免孤独
难免孤独 2020-11-22 01:33

I\'m trying to write a custom servlet (for AJAX/JSON) in which I would like to reference my @ManagedBeans by name. I\'m hoping to map:

http://host

6条回答
  •  迷失自我
    2020-11-22 01:48

    You can get the managed bean by passing the name:

    public static Object getBean(String beanName){
        Object bean = null;
        FacesContext fc = FacesContext.getCurrentInstance();
        if(fc!=null){
             ELContext elContext = fc.getELContext();
             bean = elContext.getELResolver().getValue(elContext, null, beanName);
        }
    
        return bean;
    }
    

提交回复
热议问题