• 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

Scopes

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a request scope backing bean.
Whenever I submit an action (call a backing bean method by pressing a button), it first gets to the constructor, initialize the bean, then goes to the set methods (if needed), and only at the end it arrives to the desired method.
Is this happening because my bean is of scope request?
How can I avoid this kind of behavior? (I don't want it to get to the constructor whenever I submit an action!)

And in general: When should I use session, application or request scopes?

Thanks a lot,
Efrat
 
Saloon Keeper
Posts: 27762
196
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
Yes, your problem is your scope. Objects in request scope are created when the user submits a web request, their features are used, then the object is discarded. The next request causes the whole process to be repeated.

If you want information that persists between requests, use session scope to hold per-user data or application scope to hold data common to all users in the application. It's legal - and often useful - to have multiple backing beans in multiple scopes at the same time, too.
 
Efrat Bar-Nahum
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, that makes things a bit clearer...

Efrat
 
Efrat Bar-Nahum
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well....
After checking a bit I noticed that changing the scope to session causes me some other problems.
My JSF page can be loaded from different locations in the application.
For example, there is a button in page a, and a button in page b.
Pressing these buttons loads the same "problematic" JSF, but with different parameters.
In these cases (when loaded from different pages), I do want the bean to reconstruct itself.
But now after I changed the scope to session it doesn't.
How can I call the constructor or other method in the bean? (using the body onload causes a loop).
Do I have to kill the session to make it work??

Please help,
Thanks,
Efrat
 
Space pants. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic