如何以编程方式注册JSF托管bean? [英] How to register a JSF managed bean programmatically?
问题描述
我想以编程方式(从Servlet init()内部)将Managed Bean类注册/添加到应用程序范围. 如何使用JSF 1.2做到这一点?
Servletinit()
中的
因此,它涉及一个非JSF请求. FacesContext#getCurrentInstance()
在这里将返回null
,因此在这里对您没有用.
很高兴知道JSF应用程序范围的托管Bean基本上存储为 就是这样. I'd like to register/add a Managed Bean class programmatically (from within a Servlet init()) into application scope.
How can I do that with JSF 1.2? from within a Servlet So, it concerns a non-JSF request. The It's good to know that JSF application scoped managed beans are basically stored as an attribute of the That's it. It'll be available in JSF by 这篇关于如何以编程方式注册JSF托管bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!ServletContext
的属性.在init()
方法中,继承的#{managedBeanName}
可以在JSF中使用.
init()
FacesContext#getCurrentInstance()
would return null
here, so it's of no use for you here. ServletContext
. In the init()
method you've the ServletContext
at your hands by the inherited getServletContext()
method. So, the following should do:@Override
public void init() {
getServletContext().setAttribute("managedBeanName", new BackingBean());
}
#{managedBeanName}
.