Java – how to programmatically register JSF managed beans?
•
Java
I want to programmatically register / add the managed bean class to the application scope (from servlet init())
Solution
Therefore, it involves a non - JSF request Facescontext#getcurrentinstance () returns null here, so it's useless here
It's nice to know that JSF application - wide managed beans are basically stored as ServletContext properties In the init () method, your ServletContext is in your hands by the inherited getservletcontext () method Therefore, the following should be done:
@Override public void init() { getServletContext().setAttribute("managedBeanName",new backingBean()); }
nothing more. It will be available in JSF through #{managedbeanname}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码