• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

backing beans vs managed beans

 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !!!
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
deepak adlakha
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so what's the difference between :-

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

OR

<h:inputText binding="#{BackingBean.someUICommandInstance}"/>
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic