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

backing beans vs managed beans

deepak adlakha
Ranch Hand

Joined: Jul 27, 2001
Posts: 325
hi,

I am new to JSF, i was reading corejsf book and i am little confused with the concept of backing beans.

It says bean which is designed to contain some or all components objects of a web form is called backing bean.

But i guess same can be achieved by managed bean also. but if i understood correctly backing bean should not hold state.

So to hold state, we use managed beans and to do any data manipulation then we use backing beans ? is this correct ?...but we have validators and conventors also avaiable to us ?...so when to use backing beans ...can we leave without them

Or can someone guide me when to use backing beans and when to use managed beans..I tried searching this forum, but i was not able to find anything matching !!!
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
Hi Deepak,

I like to think of it like this. And I don't know if this is correct or not, but it works for me.

Managed beans, are just my normal pojo's. Nothing funny.

Backing beans are my "use case beans". So I will have a LoginBean, CreateUserBean etc... that know about the "managed" bean User, or Person etc..

So the Backing/Use case bean, just becomes my controller per use case.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

Technically, a Managed Bean is a POJO that's constructed and injected by the JSF framework. It's commonly referenced by JSF pages, but it doesn't have to be. For example, it could be a Session-scope repository of data for other (non-page) resources to reference.

A Backing Bean is a bean that's referenced on JSF pages, and offhand I can't think of any way to establish that reference unless it's a ManagedBean.

So there's a difference, but for most people most of the time, it's small enough that the terms tend to get used interchangeably.
[ June 02, 2008: Message edited by: Tim Holloway ]

Customer surveys are for companies who didn't pay proper attention to begin with.
deepak adlakha
Ranch Hand

Joined: Jul 27, 2001
Posts: 325
Hi Darryl & Tim,

Thanks for replying. But i am little more confused.

Darryl,

The example you have given like Backing beans are my "use case beans". So I will have a LoginBean, CreateUserBean etc... that know about the "managed" bean User, or Person etc..

So in LoginBean use case, User class will have attributes like name,password for example and will have appropriate set and getter methods. Then what LoginBean class will have ?...textfield for display ?
Abhijeet Vaidya
Greenhorn

Joined: Apr 16, 2007
Posts: 20
Hi,

As far as I understand, managed beans are normal POJOs registered in faces-config, instantiation is managed by framework. Properties of managed beans are bound to UIComponent properties.

e.g.
<h:inputText
value="#{ManagedBean.propertyName}"/>

Whereas, backing beans are special form of managed beans where instead of values, actual UIComponents are bound to bean properties.

e.g.

<h:inputText
binding="#{BackingBean.someUICommandInstance}"/>

uses binding attribute instead of value.


Cheers!!!
~Abhijeet
deepak adlakha
Ranch Hand

Joined: Jul 27, 2001
Posts: 325
so what's the difference between :-

e.g.<h:inputText value="#{ManagedBean.propertyName}"/>

OR

<h:inputText binding="#{BackingBean.someUICommandInstance}"/>
Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
Managed Beans use 'value' . i.e., the value is output.
Backing Beans use 'binding'. It is a two way traffic. Both Input and Output.
I am also learning JSF. I am open to correction.
Sergey Smirnov
Ranch Hand

Joined: May 29, 2003
Posts: 167
Managed bean is about how a java bean is created and initialized. As you know, jsf uses the lazy initialization model. It means that the bean in the particular scope is created and initialized not at the moment when the scope is started, but on-demand, i.e. when the bean is first time required.

Backing bean is about the role a particular managed bean plays. This is a role to be a server-side representation of the components located on the page. Usually, the backing beans have a request scope, but it is not a restriction.

If you use or try to work with Java Studio Creator, you can find the backing bean work more explicitly. The same for Shale, because it is designed by the same architect, that led the first JSF specification where those terms were introduced. Generally, it is not required by specification to bind all the components with the properties of the backing bean, so, on practice, the differentiation between the backing bean and managed bean is not evident. Sometimes people call all the beans like backing beans even they are just used for value binding. There is no a thumb rule here, just because the JSF specification has no explicit definition for those terms.

Source: http://forum.java.sun.com/thread.jspa?threadID=765889&messageID=4366727
[ June 05, 2008: Message edited by: Sergey Smirnov ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: backing beans vs managed beans