• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Controll session-scoped beans instantiation

 
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
 
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
 
Saloon Keeper
Posts: 22784
153
Android Eclipse IDE Tomcat Server Redhat Java 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic