Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF Managed Beans in a Servlet

Tags:

servlets

jsf

Is there a way to access JSF managed beans from a servlet?

like image 782
DD. Avatar asked Apr 19 '10 17:04

DD.


People also ask

What is JSF managed bean?

Managed Bean is a regular Java Bean class registered with JSF. In other words, Managed Beans is a Java bean managed by JSF framework. Managed bean contains the getter and setter methods, business logic, or even a backing bean (a bean contains all the HTML form value). Managed beans works as Model for UI component.

What is meant by managed beans?

Managed beans are container-managed objects with minimal supported services, such as resource injection, life cycle callbacks and interceptors, and have the following characteristics: A managed bean does not have its own component-scoped java:comp namespace.

What is the difference between managed bean and backing bean?

1) BB: A backing bean is any bean that is referenced by a form. MB: A managed bean is a backing bean that has been registered with JSF (in faces-config. xml) and it automatically created (and optionally initialized) by JSF when it is needed.

How can I get managed bean from FacesContext?

FacesContext context = FacesContext. getCurrentInstance(); ELContext elContext = context. getELContext(); ProfileBean profileBean = (ProfileBean) elContext.


1 Answers

In a Servlet, you can get request scoped beans by:

Bean bean = (Bean) request.getAttribute("beanName");

and session scoped beans by:

Bean bean = (Bean) request.getSession().getAttribute("beanName);

and application scoped beans by:

Bean bean = (Bean) getServletContext().getAttribute("beanName");
like image 106
BalusC Avatar answered Sep 22 '22 11:09

BalusC