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

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

 
Ranch Hand
Posts: 35
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to everybody,
How can I do that?
I tryed with these:

and


but it seams they don't work.
thanks
Massimo
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Take a look at this recent post: https://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
Posts: 35
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
massimo tarantelli
Ranch Hand
Posts: 35
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic