Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is a managed bean constructor called?

When is a managed Bean constructor called? Is it called only once?

Thank you!

like image 203
Luciane Avatar asked Dec 20 '13 14:12

Luciane


1 Answers

A managed bean constructor invocation is performed by the JSF Lifecycle Process. It depends which scope is declared for the bean. If the scope of the Managed Bean is "request" than JSF provides one bean instance for each request. After the request has finished the state of the bean is undefined.

Another scope is the session scope which means that one bean instance is provided for the complete web session. So you are responsible for managing a correct bean state for the whole session.

There exist some other scopes have a look at JSF Lifecycle and Scopes of ManagedBeans.

Additionally hava a look at the FacesContext and FacesServlet: Nice description is here: Lifecycle of FacesContext?

like image 77
Diversity Avatar answered Oct 23 '22 11:10

Diversity