Event-Processing Life Cycle
Netbeans’s application model places several methods in the page bean that tie into the JSF event-processing life cycle. These methods represent four major stages—initialization, preprocessing, prerendering and destruction. Each corresponds to a method in the page bean class—init, preprocess, prerender and destroy, respectively. Netbeans automatically creates these methods, but you can customize them to handle life-cycle processing tasks, such as rendering an element on a page only if a user clicks a button.
The init method (Fig. 26.3, lines 140–154) is called by the JSP container the first time the page is requested and on postbacks. A postback occurs when form data is sub-mitted, and the page and its contents are sent to the server to be processed. Method init invokes its superclass version (line 142) then tries to call the method _init (declared in lines 23–25). The _init method is also automatically generated and handles component initial-ization tasks (if there are any), such as setting the options for a group of radio buttons.
The preprocess method (lines 157–159) is called after init, but only if the page is processing a postback. The prerender method (lines 162–166) is called just before a page is rendered (i.e., displayed) by the browser. This method should be used to set component properties; properties that are set sooner (such as in method init) may be overwritten before the page is actually rendered by the browser. For this reason, we set the value of clockText in the prerender method.
Finally, the destroy method (lines 169–171) is called after the page has been ren-dered, but only if the init method was called. This method handles tasks such as freeing resources used to render the page.
Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.