Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Forcing managed bean into session scope

Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all-
I have a session scoped backing bean which is never actually referenced in the view. It is simply used to store EJBs, which can be retrieved by my request scoped beans (which are referenced in my .xhtml files).

However, how can I actually get this session bean into the FacesContext's session scope map? Since it's never actually used on the page, it's never loaded into session.

I realize I could put a dummy variable into the session scope bean and tie it to a hidden field in the view. However, that seems really hacky...any suggestions?

Thanks in advance,
Saloon Keeper
Posts: 22017
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's not really a backing bean if there's no view that it backs - it's just a managed bean.

On the other hand, it sounds like this is a service provider for the request-scoped beans. Specifically as a dispenser for EJBs, though I'd consider pushing the EJBs back a level and letting it provide business logic using the EJBs it's keeping.

Anyway, from that point of view, it seems reasonable that you'd want to inject it into the request backing beans, so not hackey.

If that doesn't suit, remember that there's nothing magic about session-scoped beans managed by the JSF framework compared with session-scoped beans created the old-fashioned manual way. The only difference is that JSF takes over the job of getting them instantiated.
Zack Marrapese
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the informative reply, Tim! How would I instantiate the session bean the old fashioned way? I am relatively new to JSF, and haven't instantiated them manually before.
I want my playground back. Here, I'll give you this tiny ad for it:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic