Forums Register Login

Controll session-scoped beans instantiation

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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.
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1896 times.
Similar Threads
stereotypes in sequence diagrams (in Rose)
Beginner Problem: son & parent
Storing Session Values in Swing (Possible?)
EntityManager.flush not flushing
HTML -> Servlet -> java bean -> JSP
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:39:49.