JSF managed bean onload problem
In my application when the managed beans are initialized I use the constructor of a managed bean to load data from the data base and i want to use it in other managed beans.I dont want to fetch the data again as i am using the same data in other pages. But when i reference the managed bean(having the fetched data) in other beans using
FacesContext facesContext=FacesContext.getCurrentInstance();
Application application=facesContext.getApplication();
CSListBackingBean userBean=(CSListBackingBean )application.createValueBinding("#{listBackingBean}").getValue(facesContext);
The constructor is invoked again.I am working in RAD6 with Websphere portal server 5.1. I am using JSR 168 with JSF of Sun RI.
Thanks in advance
[759 byte] By [
termia] at [2007-11-27 9:53:07]

# 1
Is it a request, session or application scoped bean? If session scoped for example, then just doMyBean myBean = (MyBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("myBean");
This shouldn't create a new instance and therefore invoke the constructor.
# 2
Thanks for the reply
It is in the session scope. Sorry ,the code that u gave is not working.The constructor is invoked again.It shows like /pages/myPages/Admin.jsp: init and the contructor is invoked.I have used <h:selectOneMenu >which has <f:selectItems> in the Admin.jsp which refers to a list attribute in the managed bean whose constructor is invoked.The values in the list should be populated only once with a fetch from the data base.I have referenced the other managed bean in the bean being used as
adminBackingBean.cSBean.clientList."cSBean" constructor is being invoked.I gave ur code in the get property of the cSBean
Thanks in advance
# 4
It could be that he is actually creating a new session, in which case the constructor would be invoked again.At what level do you need the constructor invoked, application (i.e. once) or per session?