You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by santosh chouhan <ch...@gmail.com> on 2008/11/29 08:26:35 UTC

Difference between backing bean and model bean

Hello all,
I studied somewhere backing bean and model bean, so what is difference
between the two and when to use where and which is called first.
Thanks in advance.

Regards
Santosh chouhan

Re: Difference between backing bean and model bean

Posted by Gerhard Petracek <ge...@gmail.com>.
hello,

hazem just corrected the previous statements for most use-cases (not for all
use-cases).

regards,
gerhard



2008/11/29 Guy Bashan <gu...@gmail.com>

> hi,
> this is not entirly correct, since there are cases in which jsf doesn't do
> all the hard work. two cases that I met more than once are:
> 1) presenting report output in a datatable according to filtered criteria.
> 2) saving state of one screen even if validation fails and restoring this
> state after doing some action in another page.
>
> i admit it is not jsf responsibility to give direct answers to these
> issues, but it is the kind of cases I fall back to good old servletRequest
> or use some comlementing technology.
>
> Sent from my iPhone
>
> On 29/11/2008, at 17:55, "Hazem Saleh" <ha...@apache.org> wrote:
>
> Hello mates,
>
> I just want to note that one of the JSF good things is to allow developers
> to bind the components directly with model without
> having to directly hack the request parameters, and model methods should be
> called in the action of the components (INVOKE_APPLICATION phase).
>
> JSF is a component-oriented framework. JSF application developer should not
> care about (ServletRequest) as binding is done automatically by the
> framework.
> So if one finds (him/her)self having to talk directly with (ServletRequest)
> inside the JSF application then (s)he should do some refactoring to
> eliminate these direct calls.
>
> Thank you mates.
>
> On Sat, Nov 29, 2008 at 3:09 PM, santosh chouhan <<c...@gmail.com>
> chouhan.santosh32@gmail.com> wrote:
>
>> Thank you very much Justinas.
>>
>> Santosh Chouhan
>>
>>
>> On Sat, Nov 29, 2008 at 6:20 PM, Justinas <ju...@tavatievs.eu> wrote:
>>
>>> santosh chouhan wrote:
>>>
>>>> Hello Justinas,
>>>> Which one is called  first , is there any case possible where Ui
>>>> component can directly connect to model bean . please any one give the
>>>> exactly scenario of beans when they come in action.
>>>>
>>> First called is backingbean. Then bb does some logic, and calls model.
>>> To call model method directly from UI component is bad, because, during
>>> page rendering very often bindings are called more than once. You could see
>>> that in effect when you put system.out.println("sometext") in BB setter or
>>> getter method!
>>> Backing beans are helpers, temp value storage for UI component or group
>>> of them. They take data from Model beans.
>>>
>>> Usually I put BB in request scope, and in constructor I initialize it
>>> using calls to Model classes according to request parameters. In that way,
>>> model beans are called once per request and backing bean hold values as long
>>> as it takes to render page.
>>>
>>>>  From which beans i get my form attribute ,  please make me clear all
>>>> step
>>>>
>>> h:dataTable value="#{myBB.dataModel}"
>>>
>>> BB:
>>> private DataModel dataModel;
>>> constructor:
>>>   this.dataModel = new
>>> ListDataModel(MyModel.getItemList(Contexts.getRequestParam('parent_id'));
>>>
>>> where Contexts.getRequestParam is helper function to extract post/get
>>> parameter from HttpRequest.
>>> MyModel.getItemList() - static method, returning List of items. It
>>> encapsulates required SQL and so on.)
>>>
>>> hope that clears things up!
>>>
>>> Justinas
>>>
>>
>>
>
>
> --
> Hazem Ahmed Saleh Ahmed
>
> Author of (The Definitive Guide to Apache MyFaces and Facelets):
>
> <http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/1590597370>
> http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/1590597370
>
> Web blog: <http://www.jroller.com/page/HazemBlog>
> http://www.jroller.com/page/HazemBlog
>
> [Web 2.0] Google Maps Integration with JSF:
> <http://code.google.com/p/gmaps4jsf/>http://code.google.com/p/gmaps4jsf/
>  <http://www.theserverside.com/news/thread.tss?thread_id=51250>
> http://www.theserverside.com/news/thread.tss?thread_id=51250
>
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: Difference between backing bean and model bean

Posted by Guy Bashan <gu...@gmail.com>.
hi,
this is not entirly correct, since there are cases in which jsf  
doesn't do all the hard work. two cases that I met more than once are:
1) presenting report output in a datatable according to filtered  
criteria.
2) saving state of one screen even if validation fails and restoring  
this state after doing some action in another page.

i admit it is not jsf responsibility to give direct answers to these  
issues, but it is the kind of cases I fall back to good old  
servletRequest or use some comlementing technology.

Sent from my iPhone

On 29/11/2008, at 17:55, "Hazem Saleh" <ha...@apache.org> wrote:

> Hello mates,
>
> I just want to note that one of the JSF good things is to allow  
> developers to bind the components directly with model without
> having to directly hack the request parameters, and model methods  
> should be called in the action of the components (INVOKE_APPLICATION  
> phase).
>
> JSF is a component-oriented framework. JSF application developer  
> should not care about (ServletRequest) as binding is done  
> automatically by the framework.
> So if one finds (him/her)self having to talk directly with  
> (ServletRequest) inside the JSF application then (s)he should do  
> some refactoring to eliminate these direct calls.
>
> Thank you mates.
>
> On Sat, Nov 29, 2008 at 3:09 PM, santosh chouhan <chouhan.santosh32@gmail.com 
> > wrote:
> Thank you very much Justinas.
>
> Santosh Chouhan
>
>
> On Sat, Nov 29, 2008 at 6:20 PM, Justinas <ju...@tavatievs.eu>  
> wrote:
> santosh chouhan wrote:
> Hello Justinas,
> Which one is called  first , is there any case possible where Ui  
> component can directly connect to model bean . please any one give  
> the exactly scenario of beans when they come in action.
> First called is backingbean. Then bb does some logic, and calls model.
> To call model method directly from UI component is bad, because,  
> during page rendering very often bindings are called more than once.  
> You could see that in effect when you put  
> system.out.println("sometext") in BB setter or getter method!
> Backing beans are helpers, temp value storage for UI component or  
> group of them. They take data from Model beans.
>
> Usually I put BB in request scope, and in constructor I initialize  
> it using calls to Model classes according to request parameters. In  
> that way, model beans are called once per request and backing bean  
> hold values as long as it takes to render page.
>
>  From which beans i get my form attribute ,  please make me clear  
> all step
> h:dataTable value="#{myBB.dataModel}"
>
> BB:
> private DataModel dataModel;
> constructor:
>   this.dataModel = new  
> ListDataModel( 
> MyModel.getItemList(Contexts.getRequestParam('parent_id'));
>
> where Contexts.getRequestParam is helper function to extract post/ 
> get parameter from HttpRequest.
> MyModel.getItemList() - static method, returning List of items. It  
> encapsulates required SQL and so on.)
>
> hope that clears things up!
>
> Justinas
>
>
>
>
> -- 
> Hazem Ahmed Saleh Ahmed
>
> Author of (The Definitive Guide to Apache MyFaces and Facelets):
> http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/1590597370
>
> Web blog: http://www.jroller.com/page/HazemBlog
>
> [Web 2.0] Google Maps Integration with JSF:
> http://code.google.com/p/gmaps4jsf/
> http://www.theserverside.com/news/thread.tss?thread_id=51250

Re: Difference between backing bean and model bean

Posted by Hazem Saleh <ha...@apache.org>.
Hello mates,

I just want to note that one of the JSF good things is to allow developers
to bind the components directly with model without
having to directly hack the request parameters, and model methods should be
called in the action of the components (INVOKE_APPLICATION phase).

JSF is a component-oriented framework. JSF application developer should not
care about (ServletRequest) as binding is done automatically by the
framework.
So if one finds (him/her)self having to talk directly with (ServletRequest)
inside the JSF application then (s)he should do some refactoring to
eliminate these direct calls.

Thank you mates.

On Sat, Nov 29, 2008 at 3:09 PM, santosh chouhan <
chouhan.santosh32@gmail.com> wrote:

> Thank you very much Justinas.
>
> Santosh Chouhan
>
>
> On Sat, Nov 29, 2008 at 6:20 PM, Justinas <ju...@tavatievs.eu> wrote:
>
>> santosh chouhan wrote:
>>
>>> Hello Justinas,
>>> Which one is called  first , is there any case possible where Ui
>>> component can directly connect to model bean . please any one give the
>>> exactly scenario of beans when they come in action.
>>>
>> First called is backingbean. Then bb does some logic, and calls model.
>> To call model method directly from UI component is bad, because, during
>> page rendering very often bindings are called more than once. You could see
>> that in effect when you put system.out.println("sometext") in BB setter or
>> getter method!
>> Backing beans are helpers, temp value storage for UI component or group of
>> them. They take data from Model beans.
>>
>> Usually I put BB in request scope, and in constructor I initialize it
>> using calls to Model classes according to request parameters. In that way,
>> model beans are called once per request and backing bean hold values as long
>> as it takes to render page.
>>
>>>  From which beans i get my form attribute ,  please make me clear all
>>> step
>>>
>> h:dataTable value="#{myBB.dataModel}"
>>
>> BB:
>> private DataModel dataModel;
>> constructor:
>>   this.dataModel = new
>> ListDataModel(MyModel.getItemList(Contexts.getRequestParam('parent_id'));
>>
>> where Contexts.getRequestParam is helper function to extract post/get
>> parameter from HttpRequest.
>> MyModel.getItemList() - static method, returning List of items. It
>> encapsulates required SQL and so on.)
>>
>> hope that clears things up!
>>
>> Justinas
>>
>
>


-- 
Hazem Ahmed Saleh Ahmed

Author of (The Definitive Guide to Apache MyFaces and Facelets):
http://www.amazon.com/Definitive-Guide-Apache-MyFaces-Facelets/dp/1590597370

Web blog: http://www.jroller.com/page/HazemBlog

[Web 2.0] Google Maps Integration with JSF:
http://code.google.com/p/gmaps4jsf/
http://www.theserverside.com/news/thread.tss?thread_id=51250

Re: Difference between backing bean and model bean

Posted by santosh chouhan <ch...@gmail.com>.
Thank you very much Justinas.

Santosh Chouhan

On Sat, Nov 29, 2008 at 6:20 PM, Justinas <ju...@tavatievs.eu> wrote:

> santosh chouhan wrote:
>
>> Hello Justinas,
>> Which one is called  first , is there any case possible where Ui component
>> can directly connect to model bean . please any one give the exactly
>> scenario of beans when they come in action.
>>
> First called is backingbean. Then bb does some logic, and calls model.
> To call model method directly from UI component is bad, because, during
> page rendering very often bindings are called more than once. You could see
> that in effect when you put system.out.println("sometext") in BB setter or
> getter method!
> Backing beans are helpers, temp value storage for UI component or group of
> them. They take data from Model beans.
>
> Usually I put BB in request scope, and in constructor I initialize it using
> calls to Model classes according to request parameters. In that way, model
> beans are called once per request and backing bean hold values as long as it
> takes to render page.
>
>>  From which beans i get my form attribute ,  please make me clear all step
>>
> h:dataTable value="#{myBB.dataModel}"
>
> BB:
> private DataModel dataModel;
> constructor:
>   this.dataModel = new
> ListDataModel(MyModel.getItemList(Contexts.getRequestParam('parent_id'));
>
> where Contexts.getRequestParam is helper function to extract post/get
> parameter from HttpRequest.
> MyModel.getItemList() - static method, returning List of items. It
> encapsulates required SQL and so on.)
>
> hope that clears things up!
>
> Justinas
>

Re: Difference between backing bean and model bean

Posted by Justinas <ju...@tavatievs.eu>.
santosh chouhan wrote:
> Hello Justinas,
> Which one is called  first , is there any case possible where Ui 
> component can directly connect to model bean . please any one give the 
> exactly scenario of beans when they come in action.
First called is backingbean. Then bb does some logic, and calls model.
To call model method directly from UI component is bad, because, during 
page rendering very often bindings are called more than once. You could 
see that in effect when you put system.out.println("sometext") in BB 
setter or getter method!
Backing beans are helpers, temp value storage for UI component or group 
of them. They take data from Model beans.

Usually I put BB in request scope, and in constructor I initialize it 
using calls to Model classes according to request parameters. In that 
way, model beans are called once per request and backing bean hold 
values as long as it takes to render page.
>   From which beans i get my form attribute ,  please make me clear all 
> step
h:dataTable value="#{myBB.dataModel}"

BB:
private DataModel dataModel;
constructor:
    this.dataModel = new 
ListDataModel(MyModel.getItemList(Contexts.getRequestParam('parent_id'));

where Contexts.getRequestParam is helper function to extract post/get 
parameter from HttpRequest.
MyModel.getItemList() - static method, returning List of items. It 
encapsulates required SQL and so on.)

hope that clears things up!

Justinas

RE: Difference between backing bean and model bean

Posted by "Nutulapati, Krishna" <KN...@ussco.com>.
Here by I'm sharing my understanding over backing bean,model bean and
manged bean. 
You will get your form attributes from/to  backing bean. Later Backing
bean can be interacted with Model objects (Domain model)through service
layer. 
There is one more type of bean called managed bean.(Managed bean may or
may not be binded with jsf page,but backing bean ). Backing bean can be
called as a type of managed bean. Managed bean can also be some other
bean,having interaction from backing bean. All managed beans will be
configured in facesconfg.xml. 
Krishna


________________________________

From: santosh chouhan [mailto:chouhan.santosh32@gmail.com] 
Sent: Saturday, November 29, 2008 6:06 AM
To: MyFaces Discussion
Subject: Re: Difference between backing bean and model bean


Hello Justinas,
Which one is called  first , is there any case possible where Ui
component can directly connect to model bean . please any one give the
exactly scenario of beans when they come in action.
  From which beans i get my form attribute ,  please make me clear all
step 

Thanks in advance

Thanks & Regards
Santosh Chouhan


On Sat, Nov 29, 2008 at 4:55 PM, Justinas <ju...@tavatievs.eu> wrote:


	santosh chouhan wrote:
	

		Hello all,
		

	hi 
	
	

		I studied somewhere backing bean and model bean, so what
is difference between the two and when to use where and which is called
first.
		Thanks in advance.
		
		

	think Backing Bean as GUI component extension(helps to integrate
with domain model) and Model bean is a domain model class witch is not
related in any way to GUI
	
	
	Justinas
	



Re: Difference between backing bean and model bean

Posted by santosh chouhan <ch...@gmail.com>.
Hello Justinas,
Which one is called  first , is there any case possible where Ui component
can directly connect to model bean . please any one give the exactly
scenario of beans when they come in action.
  From which beans i get my form attribute ,  please make me clear all step

Thanks in advance

Thanks & Regards
Santosh Chouhan

On Sat, Nov 29, 2008 at 4:55 PM, Justinas <ju...@tavatievs.eu> wrote:

> santosh chouhan wrote:
>
>> Hello all,
>>
> hi
>
>> I studied somewhere backing bean and model bean, so what is difference
>> between the two and when to use where and which is called first.
>> Thanks in advance.
>>
>>  think Backing Bean as GUI component extension(helps to integrate with
> domain model) and Model bean is a domain model class witch is not related in
> any way to GUI
>
>
> Justinas
>

Re: Difference between backing bean and model bean

Posted by Justinas <ju...@tavatievs.eu>.
santosh chouhan wrote:
> Hello all,
hi
> I studied somewhere backing bean and model bean, so what is difference 
> between the two and when to use where and which is called first.
> Thanks in advance.
>
think Backing Bean as GUI component extension(helps to integrate with 
domain model) and Model bean is a domain model class witch is not 
related in any way to GUI


Justinas