aspose file tools*
The moose likes JSF and the fly likes Context mapping between backing/managed beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Context mapping between backing/managed beans" Watch "Context mapping between backing/managed beans" New topic
Author

Context mapping between backing/managed beans

Mark Kelsall
Greenhorn

Joined: Apr 23, 2011
Posts: 19
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
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mark Kelsall
Greenhorn

Joined: Apr 23, 2011
Posts: 19
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

Joined: Jun 25, 2001
Posts: 16250
    
  21

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Context mapping between backing/managed beans