| Author |
Controll session-scoped beans instantiation
|
Victor Dolirio
Ranch Hand
Joined: Aug 21, 2008
Posts: 56
|
|
Hi ranchers,
When I'm using my backed bean in scope session, there are centain situations that I would like to create a new instance of this bean in the session. Something like to restart the "state" of my bean. There is a direct way (via jsf api) to accomplish it? I'm wondering if exists a way to do this directly in the pages or in a declarative way...
[]s,
Victor Dolirio
|
If happen something bad in you life, don't ask God why it happened. Ask for what.
SCJP 5 (80%) - SCWCD 5 (91%) - SCBCD & SCJD coming soon...
|
 |
Daniel Almeida
Greenhorn
Joined: Mar 16, 2010
Posts: 7
|
|
Why get a new instance of the entire session bean? You can get new instances of the variables of your bean. Like this:
When you need to "restart the state" of your bean you only need to call the restart method.
Hope it's help,
[]
Daniel Almeida
|
 |
Victor Dolirio
Ranch Hand
Joined: Aug 21, 2008
Posts: 56
|
|
Daniel,
Thanks for regards. Could I call this method without an user action? i.e. When the user enter the url in browser, before it gets rendered?
[]s,
Victor Dolirio
|
 |
Daniel Almeida
Greenhorn
Joined: Mar 16, 2010
Posts: 7
|
|
Victor Dolirio wrote:Daniel,
Thanks for regards. Could I call this method without an user action? i.e. When the user enter the url in browser, before it gets rendered?
[]s,
Victor Dolirio
Ok, you can implement a Phase Listener for intercept the life cycle render response phase, but I'm not sure this is the best option.
[]s
Daniel Almeida
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 11740
|
|
You can replace an existing session object with a newly-constructed session object by obtaining the HttpSession and invoking the setAttribute method on it. But I don't recommend that.
You can also "restart" an object, which is something I do more often. For that, I usually define a method named "init()" in the session object, and invoke it when I want to (re)initialize the object. Often the constructor invokes init() as well, just to put everything in one convenient place.
JSF isn't about URLs. It's about model/view/controller interactions. In practical terms, that means that the most common need to "restart" an object is that you're about to begin using it for some sort of business workflow process. And that's generally done from an action method somewhere, often in some other bean, such as a menu-managing bean.
|
A lot the of modern-day software development platforms are designed to permit parcelling out work to those with the best aptitude for it. A lot of modern-day business is predicated on making one person do all the work, regardless of aptitude.
|
 |
 |
|
|
subject: Controll session-scoped beans instantiation
|
|
|