The @ManagedBean annotation told JavaServer Faces (JSF) to create a Java class, register it under a name and manage its lifecycle, so that Facelets pages could read its properties and call its methods through Expression Language (EL) such as #{helloBean.name}. It is deprecated since JSF 2.3 and removed in Jakarta Faces 4.0 (Jakarta EE 10). New code should use CDI with @Named and a CDI scope instead.
The role of a managed bean has not changed: it is the controller layer between a Faces view and your business logic. Only the annotations that create it have moved, so everything below shows the legacy form first and then the current replacement.
javax.faces.bean.ManagedBean marked a class as a JSF-managed backing bean. At startup the Faces runtime scanned for annotated classes and registered each one under a name. By default the name was the class name with a lowercase first letter, so HelloBean became helloBean. You could override it with @ManagedBean(name = "hello").
A managed bean gave a view three things:
value="#{helloBean.name}" calls getName() when rendering and setName() when the form is submitted.action="#{helloBean.greet}" calls a method when a command component is invoked.It also supported @ManagedProperty to inject another managed bean or a value. That mechanism was limited compared with CDI, which is one reason the specification dropped it.
This is the classic form. It compiles only against JSF 2.x and Faces 3.x style APIs that still contain the old javax.faces.bean package.
greet() returns void, so the same view is shown again after submit and the new greeting is rendered. If an action method returns a String, JSF treats it as a navigation outcome (a view id), not as display text.
Faces 2.3 deprecated the whole javax.faces.bean package in favor of CDI. Jakarta Faces 4.0 removed it. The timeline matters when you migrate:
| Specification | Namespace | Status of @ManagedBean |
|---|---|---|
| JSF 2.0 to 2.2 | javax.faces | Standard way to declare backing beans |
| JSF 2.3 (Java EE 8) | javax.faces | Deprecated, CDI recommended |
| Jakarta Faces 3.0 (Jakarta EE 9) | jakarta.faces | Present but deprecated |
| Jakarta Faces 4.0 (Jakarta EE 10) | jakarta.faces | Removed |
The reasoning is simple: Jakarta EE already has one component model, CDI. Two parallel bean containers caused duplicated scopes, injection that worked in one and not the other, and confusing behavior in application servers.
Today a backing bean is a CDI bean with a name. The scope annotation comes from jakarta.enterprise.context, except the view scope, which Faces itself provides.
@Named without a value uses the same default name as before (helloBean), so existing EL expressions keep working. CDI must be active for the archive; a WEB-INF/beans.xml with bean-discovery-mode="annotated" works on every runtime.
The Facelets page in current Faces uses the jakarta.faces.* namespaces:
On Faces 2.x and 3.x the tag library namespace is http://xmlns.jcp.org/jsf/html (or http://java.sun.com/jsf/html in older pages). Faces 4.0 uses jakarta.faces.html.
The scopes keep their meaning, but the annotations differ:
| Lifetime | Legacy annotation | Current annotation |
|---|---|---|
| One HTTP request | javax.faces.bean.RequestScoped | jakarta.enterprise.context.RequestScoped |
| One browser session | javax.faces.bean.SessionScoped | jakarta.enterprise.context.SessionScoped |
| Whole application | javax.faces.bean.ApplicationScoped | jakarta.enterprise.context.ApplicationScoped |
| One Faces view (postbacks to the same page) | javax.faces.bean.ViewScoped | jakarta.faces.view.ViewScoped |
| Multi-page flow | not available | jakarta.faces.flow.FlowScoped or jakarta.enterprise.context.ConversationScoped |
Two rules prevent common bugs. First, session and view scoped beans must implement Serializable, because the container may passivate them. Second, never mix the legacy javax.faces.bean.ViewScoped with @Named: the scope would be silently ignored and the bean would behave as request scoped.
@ManagedBean with @Named, keeping the name if you set one explicitly.javax.faces.bean.*Scoped import with the CDI or jakarta.faces.view.ViewScoped equivalent.@ManagedProperty("#{otherBean}") with @Inject on the field.javax.faces imports to jakarta.faces and javax.inject to jakarta.inject when you move to Jakarta EE 9 or later.No. It is deprecated since JSF 2.3 and absent from Jakarta Faces 4.0, so it will not compile against current Jakarta EE 10 or newer runtimes. Use @Named with a CDI scope.
@ManagedBean registered a bean in the Faces-specific container. @Named makes a CDI bean addressable from EL, and CDI beans can also be injected, intercepted and observed with events anywhere in the application.
The simple class name with the first letter lowercased, for example UserSessionBean becomes userSessionBean. Both @ManagedBean and @Named use this rule unless you set a name.
Properties used in EL need them, because EL resolves name through getName() and setName(). A field alone is not visible to the view.
A JSF managed bean connects a Facelets view to Java code through EL bindings and a scope. @ManagedBean created such beans in JSF 2.x, but it is deprecated since 2.3 and removed in Jakarta Faces 4.0. Use @Named with jakarta.enterprise.context scopes, and jakarta.faces.view.ViewScoped for per-view state.