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 !!!
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 ]
Sometimes the only way things ever got fixed is because people became uncomfortable.
Thanks for replying. But i am little more confused.
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 ?
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.