Oracle ADF framework is a container in the sense that it contains and manages the lifecycle and configuration of application objects. In the ADF framework, you can declare how each of your application objects should be created, how they should be configured, and how they should be associated with each other.
Managed BeansA managed bean - sometimes simply referred to as an MBean - is a type of JavaBean, created with dependency injection and registered with the application using various configuration files. Managed Beans are particularly used in the Java Management Extensions technology. But with Java EE 6, the specification provides for a more detailed meaning of a managed bean.
The MBean represents a resource running in the Java virtual machine, such as an application or a Java EE technical service (transactional monitor, JDBC driver, etc.). They can be used for getting and setting applications configuration (pull), for collecting statistics (pull) (e.g. performance, resources usage, problems) and notifying events (push) (e.g. faults, state changes).
Backing beans are managed beans that contain logic and properties for UI components on a JSF page. In a standard JSF application, managed beans are registered in the faces-config.xml configuration file.
Three characteristics of a managed bean:
- Name — way to reference bean in JSF application
- Class — fully qualified class name of bean
- Scope — how long the bean will live (i.e., application, session, request)
The managed-bean element can contain zero or more managed-property elements (see example below), each corresponding to a property defined in the bean class. These elements are used to initialize the values of the bean properties. If you don’t want a particular property initialized with a value when the bean is instantiated, do not include a managed-property definition for it in your application configuration resource file. Read this article to learn how to use the managed-property element.
Dependency InjectionThe key benefit of Dependency Injection (DI) is loose coupling. When applying DI, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. In other words, dependencies are injected into objects. So, DI means an inversion of responsibility with regard to how an object obtains references to collaborating objects. With DI, your application objects are freed from the burden of fetching their own dependencies and are able to focus on their tasks, trusting that their dependencies will be available when needed.
JavaServer Faces Managed Bean FacilityIn this article, it discusses JavaServer Faces Managed Bean Facility which is provided similarly in the ADF framework. In summary, it provides the following functionalities:
- Control of instantiation (constructor) and setter based injection of managed objects
- Control when objects are loaded (i.e., eager instantiation vs. lazy loading)
- Dependency Handling
- Lifecycle Support
- Configuration Support
Managed Beans in Fusion Web ApplicationsThe controller used in ADF framework is ADF Controller (ADFc). It is an extension to JSF page flow engine. It allows the definition of managed beans with additional memory scopes:
- Application scope
- Session scope
- Page flow scope
- Request scope
- Backing bean scope
- View scope
- faces-config.xml file
- adfc-config.xml file
- task flow definition file
<?xml version="1.0" encoding="windows-1252" ?> <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2"> <view id="TestPage"> <page>/TestPage.jspx</page> </view> <view id="Messages"> <page>/ui/page/Messages.jspx</page> </view> <managed-bean> <managed-bean-name>updateUserInfoBean</managed-bean-name> <managed-bean-class>oracle.fodemo.storefront.account.view.managed.UpdateUserInfoBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>allItemsIteratorName</property-name> <value>AvailableCategoriesShuttleListIterator</value> </managed-property> <managed-property> <property-name>allItemsValueAttrName</property-name> <value>CategoryId</value> </managed-property> <managed-property> <property-name>allItemsDisplayAttrName</property-name> <value>CategoryName</value> </managed-property> <managed-property> <property-name>allItemsDescriptionAttrName</property-name> <value>CategoryDescription</value> </managed-property> <managed-property> <property-name>selectedValuesIteratorName</property-name> <value>CustomerInterestsIterator</value> </managed-property> <managed-property> <property-name>selectedValuesValueAttrName</property-name> <value>CategoryId</value> </managed-property> <managed-property> <property-name>addressTable</property-name> <property-class>oracle.adf.view.rich.component.rich.data.RichTable</property-class> <value></value> </managed-property> </managed-bean> </adfc-config>
You can also find another managed bean example in this article. Finally, in a Fusion web application, you should use managed beans to store logic that is related to the UI rendering only. All application data and processing should be handled by logic in the business layer of the application.
- Creating and Using Managed Beans (if you use ADF Faces components in a standard JSF application)
- Using a Managed Bean in a Fusion Web Application (if you use Oracle ADF Model data binding and ADF Controller)
- JavaServer Faces (JSF) Tutorial
- Backing Bean in JSF Tutorial
- Types of Memory Scopes in Fusion Web Application
- Oracle ADF Task Flow in a Nutshell
- Using a Managed Bean in a Fusion Web Application