This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSF and the fly likes Session values of a Backing Bean in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Session values of a Backing Bean in JSF" Watch "Session values of a Backing Bean in JSF" New topic
Author

Session values of a Backing Bean in JSF

Pradeep Chavan
Greenhorn

Joined: Dec 15, 2005
Posts: 11
I have 2 managed beans in session scope. In one managed bean, i get a list of drop down values and display it on the screen. In another UI, i add values to the drop down list. When i am in the same session, when i add values to the drop down, the values do not reflect in the drop down on UI. The old session retains even though the values are inserted in the database. Any inputs on how to fetch the latest values always in the drop down list will be appreciated.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Make it a request scoped bean. Or manually access the bean in session scope and update the data. Or introduce the observer pattern so that it can get notified when new values are added then let it reload the data.
Pradeep Chavan
Greenhorn

Joined: Dec 15, 2005
Posts: 11
Hi,
Thanks for the reply. I need the bean in the session scope.
Can you post some sample code for reference ?
thanks in advance.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You can access session scoped beans by ExternalContext#getSessionMap() (which is actually backed by HttpSession attributes). The managed bean name is the map key.
Pradeep Chavan
Greenhorn

Joined: Dec 15, 2005
Posts: 11
There is a method to fetch the drop down list values in the managed bean.
So should I fetch the complete bean using the getSessionmap().get() ?
how can i get only the drop down list and upadet the values as you mentioned.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
How is obtaining a reference to a managed bean an issue? Your concern doesn't make much sense. If you don't want to access it by the sessionmap, you can also declare it as a managed property of the other bean.
 
GeeCON Prague 2014
 
subject: Session values of a Backing Bean in JSF