Formally, a managed bean has the following characteristics:

* Registered in a faces-config.xml file (not web.xml :-)

* Public class with a public zero-args constructor (i.e. a JavaBean)

When a value binding or method binding expression is evaluated, the
various scopes (request, session, application) are searched for a bean
with the same name (similar in spirit to what the <jsp:useBean> tag
does).  Otherwise, the facility will:

* Instantiate a new instance of the specified bean class

* Configure its properties via either literal values or value
  binding expressions (essentially giving you a very simple
  Dependency Injection / Inversion of Control container
  with no extra software)

* Store the new instance in the specified scope (unless you
  set it to "none", which means a new instance will be created
  for every expression evaluation.

Using managed beans in a filter, however, will be problematic -- you
need to have a FacesContext instance set up for the current request in
order to evaluate the expression, and that doesn't happen until
FacesServlet processes the request.  But you don't need a filter for
the configuration use case.

As others have stated, Shale's approach to this is quite elegant (but
of course I'm biased :-).

Craig

Reply via email to