• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session values of a Backing Bean in JSF

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic