• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scopes  RSS feed

 
Efrat Bar-Nahum
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!