Table of Contents

About

Managed Beans (also known as model objects and controllers) are lightweight container-managed objects (POJOs) with minimal requirements.

They support a small set of basic services, such as:

Jdeveloper Create Managed Bean

Components in a page are associated with managed beans that provide application logic. A managed bean is created with:

  • a constructor with no arguments,
  • a set of properties,
  • and a set of methods that perform functions for a component.

Each of the managed bean properties can be bound to one of the following:

The most common functions that managed bean methods perform include the following:

  • Validating a component’s data
  • Handling an event fired by a component
  • Performing processing to determine the next page to which the application must navigate

Registration

Annotation

  • The @ManagedBean annotation registers the managed bean as a resource with the JavaServer Faces implementation. If no name is specified, the managed beans is always accessed with the first letter of the class name in lowercase.
  • The @SessionScoped annotation registers the bean scope as session.

Configuration File

JSF - faces-config.xml

Scope

  • Request
  • Session
  • Application
  • View
  • None

Property

In a managed bean, a property consists of:

package hello;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Hello {

    final String world = "Hello World!";

    public String getworld() {
        return world;
    }
}

When bound to a component’s value, a bean property can be any of the basic primitive and numeric types or any Java object type for which the application has access to an appropriate converter. For example, a property can be of type Date if the application has access to a converter that can convert the Date type to a String and back again.

Documentation / Reference