• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Context mapping between backing/managed beans

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I have a scenario where I have a managed bean that is request scoped so I can read a variable from the URL & then query the database. I then map the required fields onto the page, works perfectly. I then however want to pass some of those details onto the next page, how can I do this? I have googled around & found a few different pages on here but I wasn't able to apply the thinking to my scenario & obviously didn't want to wake the sleeping zombies!

How can I pass a variable from a request scoped bean, on to a session scoped one?

Thanks

Mark
 
Saloon Keeper
Posts: 27489
195
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest way to do that is to inject the session-scoped bean as a Managed Property into the request-scoped bean. Then when the action method fires, you can use that injected bean's "set" property access methods to set the session data you want.

That's how Inversion of Control works. And the neat thing about it is that it's totally POJO. JSF wires the 2 beans together, but the actual bean interactions don't require any JSF-specific code at all.
 
Mark Kelsall
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

thanks for your reply (seems to be always you! lol).

Just to understand what you explained, the action method that fires, this would be the action method in the request-scoped bean?

That definitely seems like the best way to do it! To resolve the problem as quickly as possible I have unfortunately resorted to getting & setting session variables in the action methods, there's only 2 to set (I was pushed for time for a solution, what you gona do?!).

I will definitely be using that implementation in the future though! Thanks Tim!

Mark
 
Tim Holloway
Saloon Keeper
Posts: 27489
195
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

Mark Kelsall wrote:
Just to understand what you explained, the action method that fires, this would be the action method in the request-scoped bean?



Well, it could be in any backing bean. But then you'd have to inject the request-scoped bean into that bean (which would have to be request-scoped, too), then invoke a method on the original request scoped bean, so might as well keep it simple.

Manually retrieving session objects works in JSF as far as it goes, but I think you've just shown yourself that it's a lot more code and a lot less portable than having JSF do the job for you.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic