• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 26291
186
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: 26291
186
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.
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic