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?
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.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
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
it's a teeny, tiny, wafer thin ad:
a bit of art, as a gift, that will fit in a stocking