JSF and session bean
Hi to evaryone,
I've a jsf page with a session scoped bean, this is the config of the bean in faces-config:
<managed-bean>
<managed-bean-name>userBean</managed-bean-name>
<managed-bean-class>admin.userBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
i'm using this bean in a page called datiPersonali.jsf
before i call this page i call a servlet, in this servlet i'm select soma data from DB ad i'm load this data in the bean and i'm save the bean in a session variable, the code is this:
//load data from DB to bean
bean = utilBean.getDataFromDB(user);
//put the bean in a session variable called like managed bean
request.getSession().setAttribute("userBean", bean);
//redirect to jsf page
response.sendRedirect("/admin/user.jsf");
So when the page is diplayed the input text dosen't contain the value, why? In jsp page this function great, how i can solve this problem?
Thanks in advance,
Fabio.
[1108 byte] By [
fabdiba] at [2007-10-3 2:01:10]

JSF instantiates the bean for you when the jsf page references it. If you instantiate the bean yourself and set some properties, JSF probably creates another instance of the bean when the jsf page is loaded, which doesn't have the property set since it is a new instance.
You probably don't need all the work you are doing with the servlet and the request param. The JSF bean can do it. I guess you could call the method "getDataFromDB(user)" from the "admin.userBean".
Please post your jsf page and some of your session bean code if you need more help...
Fred
Hi friend,
yes Fred is correct, what you can do is : do not do the work in servelt at all and when the user logs in at that time you can read the information related to that user in managed bean in your case i guess it is "userBean". and whenever you want to retrive data from session, you can use ExternalContext to get the data (objects, values) stored in session, this is the right and corect approach of dealing with session in JSF.
Let me know if still you have any questions.
--Surya
thoughts can change everything
Message was edited by:
Surya_IND