Get JSF managed bean by name in any Servlet related class

前端 未结 6 704
难免孤独
难免孤独 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:54

    I use the following method:

    public static  T getBean(final String beanName, final Class clazz) {
        ELContext elContext = FacesContext.getCurrentInstance().getELContext();
        return (T) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, beanName);
    }
    

    This allows me to get the returned object in a typed manner.

提交回复
热议问题