Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Controll session-scoped beans instantiation  RSS feed

 
Victor Dolirio
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Daniel Almeida
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 18660
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!