Thursday, 7 May 2015

Difference between Managed Bean and Backing Bean



First of all backing beans are not entirely different from managed beans. Very unpopular thing to say, but it’s true. Backing Bean is also a managed bean with some specific settings.

 

What is a managed bean?

Managed beans are Java classes that you register with the application using various configuration files. When the JSF application starts up, it parses these configuration files and the beans are made available and can be referenced in an EL expression, allowing access to the beans' properties and methods. Whenever a managed bean is referenced for the first time and it does not already exist, the Managed Bean Creation Facility instantiates the bean by calling the default constructor method on the bean. If any properties are also declared, they are populated with the declared default values.

What is a Backing Bean?

Backing beans are managed beans that contain logic and properties for UI components on a JSF page.
The key point here is: It has a one-to-one relationship with a single JSF page.
It exposes setter and getter methods for the components contained on the page.

When you create your JSF page, if you choose to automatically expose UI components by selecting one of the choices in the Page Implementation option of the Create JSF Page dialog, JDeveloper automatically creates a backing bean (or uses a managed bean of your choice) for the page.
For each component you add to the page, JDeveloper then inserts a bean property for that component, and uses the binding attribute to bind component instances to those properties, allowing the bean to accept and return component instances.

Let’s see how to create a backing bean and what Happens when we create one.
·         Create a new Jspx page, Expand “Page Implementation” and click on “Automatically Expose UI Components……..”




·         See the structure of the blank page created. Notice the components present.



·         You can find properties present in the bean for these components.


·         Then drag adf components like panel box and input button to the page.






·         You can see that JDeveloper created two properties for the above created components.