aspose file tools*
The moose likes JSF and the fly likes Difference between Managed bean and backing bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Difference between Managed bean and backing bean" Watch "Difference between Managed bean and backing bean" New topic
Author

Difference between Managed bean and backing bean

Varun Nayudu
Ranch Hand

Joined: Jun 26, 2006
Posts: 157
Hi i have a question.

What is the difference between managed bean and backing bean?

I got the following answers googling but couldnt understand it

Ans1: Managed bean and backing bean are the same. Managed bean is about how the bean is initialised and created, where as backing bean is what role it plays a particular managed bean plays.
Managed bean are java bean that are registered in the faces-config.xml and there properties are binded to the UIcomponent values.
Backing bean are special type of managed beans whose properties are UIcomponent.


Are Backing beans not registered in the faces-config.xml ?

And the answer which i found if correct can anybody please explain?


SCJP 1.5, SCWCD 1.5
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

That answer is garbage. A backing bean can be a POJO, not some sort of JSF-specific object with JSF-specific properties (such as UIComponent). In fact, backing beans, generally should be POJOs, at least as much as possible. This whole nonsense about using binding is, as far as I can tell, leftover stale documentation and mythologies from when JSF was still being designed and no one had a better way. Binding is not needed very often these days.

When you declare a bean in faces-config.xml (or as a ManagedBean annotation), you are declaring to JSF that you want JSF to manage an instance of this Bean, and part of the faces-config description of that bean is the name that the bean will be managed under. Same thing with the ManagedBean annotation, although the annotation can assume a default name based on the bean's classname if you don't provide an explicit name.

A backing bean is simply a bean that's referenced from a JSF View. Technically, you could construct all your backing beans the hard way in servlets and store them in Session or Application attributes (Request scope is harder to do that way). But it's easier to make the backing beans be Managed Beans so that JSF does the job for you.


Customer surveys are for companies who didn't pay proper attention to begin with.
Navpreet Sidhu
Greenhorn

Joined: Jun 04, 2013
Posts: 1
Managed Bean is declared in FacesConfig.xml file and is available for all of the application.
Backing Bean which is declared in adfcConfig.xml is Hardcoded to a particular JSF page. Backing bean is Module Specific.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

Navpreet Sidhu wrote:Managed Bean is declared in FacesConfig.xml file and is available for all of the application.
Backing Bean which is declared in adfcConfig.xml is Hardcoded to a particular JSF page. Backing bean is Module Specific.


Sorry. That is not correct.

A Managed Bean is a POJO that is constructed by JSF on-demand. It is defined by faces-config.xml (or whatever override name(s) you configure into web.xml).

A Backing Bean is a POJO that is referenced by one or more JSF View Definitions. The relationship between Views and Backing Beans is not 1-to-1, it's many-to-many. A single View can (and often does) reference more than one backing bean, and a single backing bean may be referenced by more than one View.

Backing Beans are almost always Managed Beans and vice versa, since JSF uses the Managed Bean functionality to construct Backing Beans as needed on demand.

But I doubt any of the original participants in this discussion are interested anymore. This thread was last updated in 2011 and they've probably moved on.
 
jQuery in Action, 2nd edition
 
subject: Difference between Managed bean and backing bean