Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Forcing managed bean into session scope

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
~Zack
 
Saloon Keeper
Posts: 25843
184
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic