wood burning stoves 2.0*
The moose likes JSF and the fly likes How can I get a viewScoped bean from a request bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How can I get a viewScoped bean from a request bean? " Watch "How can I get a viewScoped bean from a request bean? " New topic
Author

How can I get a viewScoped bean from a request bean?

massimo tarantelli
Ranch Hand

Joined: Jun 19, 2012
Posts: 35

Hello to everybody,
How can I do that?
I tryed with these:

and


but it seams they don't work.
thanks
Massimo
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

Take a look at this recent post: http://www.coderanch.com/t/588300/JSF/java/More-than-one-ManagedProperty

but be sure to take into account Tim's comments. The rule is that the scope of the property must be no less than
that of the containing bean, so if you were trying to do it the other way round it wouldn't work - if I've got it
right that is. Also if you were using CDI you'd simply @Inject one bean into the other.

Regards,
Brendan.
massimo tarantelli
Ranch Hand

Joined: Jun 19, 2012
Posts: 35

Thanks for the answer,
I would like to add an other important detail.
In my request bean i don't want to create a new view scoped bean, but i would like to get a value that was previously setted.
thanks
Massimo
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
That's what @ManagedProperty does - it's the JSF managed bean mechanism for injecting one bean into another and if I'm
reading this correctly does exactly what you want. I recently came across a scenario where someone was trying to use this
mechanism when using client state saving (javax.faces.STATE_SAVING_METHOD=client) and it wouldn't work but was ok
with javax.faces.STATE_SAVING_METHOD=server.



Regards,
Brendan.
massimo tarantelli
Ranch Hand

Joined: Jun 19, 2012
Posts: 35

Thanks for the answer,
I have implemented the @ManagedProperty in my request bean and in this way I can use the viewSoped bean method, but I have noted that when i call the page linked to the requestScope bean, toghether with its constructor, it is also called the viewScoped constructor...so when I try to get the values that i had previously saved obviously I get an empty field.
In fact I "lose" the view and then the viewScoped is "distroyed".
It's possible to avoid this "distruction" and get those values or do exist some other technics ?
thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Objects in View scope are destroyed when you switch to a different view. Other than that, they behave exactly the same as session scope. And in fact, as far as I know, that's what they really are: session-scope beans with an attached destruction mechanism.

So if you want to retain your bean and its state, promote it from ViewScoped to SessionScoped.


Customer surveys are for companies who didn't pay proper attention to begin with.
massimo tarantelli
Ranch Hand

Joined: Jun 19, 2012
Posts: 35

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I get a viewScoped bean from a request bean?