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...
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...
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.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.