• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF: Bean Instantiation  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a page as simple as a form with a single text field and a submit button, all done in JSF of course. And then I have a JavaBean for this form. When does this Bean get instantiated? When the form is accessed or when the form is submitted, none of the above?
Thanks.
 
Bill Dudney
Author
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg,
It depends on how its specified in the faces-config.xml
<managed-bean-scope> session </managed-bean-scope>
will put it in the session and it will be created when the bean is first accessed.
Hope this helps...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bill Dudney:
Hi Greg,
It depends on how its specified in the faces-config.xml
<managed-bean-scope> session </managed-bean-scope>
will put it in the session and it will be created when the bean is first accessed.
Hope this helps...

Well, at what point is the bean first accessed? When I view the form or when I submit the form? And in addition to that, is it my responsibility to remove that Bean from the session if/when I don't need it anymore?
[ March 04, 2004: Message edited by: Gregg Bolinger ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would appear, after a little testing, that the Bean is accessed the first time when the Form is accessed for the first time since you are specifying a value for the textfield.
 
Bill Dudney
Author
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg,
You got it, when the page renders for the first time...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!