• 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

when is the backing bean instantiated

 
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am new to jsf so if this seems like a very basic question i do apologize.
when is the beacking bean of a jsp instantiated. i mean when are the values set using the setter methods. is it at the time of page loading , page submitting???
if i write a javascript say
function()
{

document.getElementbyId["somefield"].value="somevalue";
}
and this function gets executed on a button click(the button does only this, page is not submitted or anything), will the corresponding setSomeField() method be executed immediately??
 
Saloon Keeper
Posts: 27819
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
If you refer to a JSF View that references a previously-undefined backing bean, the framework will instantiate the bean as part of the process of preparing the view display. If it has managed properties, their setters will be called at that time. If any of the managed properties are themselved un-instantiated backing beans, those beans are first constructed and their managed properties (if any) are set.

However, thereafter the setter and getter methods may be invoked many times on a View Request/submit cycle. Which is why you should not attach complex logic or actions that have side-effects to the get/set methods.
 
Stanley Walker
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"the framework will instantiate the bean as part of the process of preparing the view display"

so does this mean that the setters will be called when the page is loaded for view?? hence if i call a javascript fucntion which resets a value of a form element without submitting the page, this value will not be available to the bean?
 
Tim Holloway
Saloon Keeper
Posts: 27819
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

Stanley Walker wrote:"the framework will instantiate the bean as part of the process of preparing the view display"

so does this mean that the setters will be called when the page is loaded for view?? hence if i call a javascript fucntion which resets a value of a form element without submitting the page, this value will not be available to the bean?



That's one reason I avoid calling JSF Views "pages". Too much confusion from non-JSF/non-MVC usage.

JSF doesn't "load a page". It takes a view definition (usually from a file, often in JSP form) and compiles it into a tree structure. This structure serves as the basis for invoking the backing bean functions. When an action is invoked, a different View definition may be requested, in which case the old tree is discarded, and a new tree is compiled using the indicated new view definition.

JSF works with discrete rendering engines that take the view tree and the JEE environment (including JSF backing beans) and runs the selected renderer against that tree. The rendering process may and often will involve calling backing bean getters. Most commonly, the renderer used is the stock HTML renderer, but other renderers are also possible, including user-defined ones.

I really recommend you find some good documentation on the JSF lifecycle, and a book or 2 on JSF wouldn't be a bad investment.
 
reply
    Bookmark Topic Watch Topic
  • New Topic