• Post Reply Bookmark Topic Watch Topic
  • New Topic

Initialize backing bean

 
Shaiju scientia
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anybody tell me when does an object of a backing bean(in request scope) get created ?
I have a few components in my jsp page,which have corresponding action listener defined in the backing bean. I have observed that a new instance of my backing bean (i.e the @PostConstruct getting called) is getting created for each events those fired from my UI.
Actually I have a DB call in my init() method which is annotated with @postconstruct.
But this method is getting called for each events that are getting fired and hence calling the DB each time. I want to avoid this.

Can anybody help ?

Shaiju
 
Bibin Zacharias
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When ever a JSF page is submited the beans which all are mentioned in the JSf page will be initiated if the bean scope is in request. This is how JSf behave. If bean scope is in session the bean will be intiated for every session.
 
Viswanath Tg
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request scope object will create new instance every time when requested from UI/ an event is fired !!!

So set the backing bean object in Session scope.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!