jsf lifecycle

Upload: hitesh-bhakuni

Post on 29-May-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 JSF Lifecycle

    1/12

    Prepared By : Rajat Gupta

  • 8/9/2019 JSF Lifecycle

    2/12

    ` The six phases of the JSF application lifecycle are

    as follows :

    1. Restore view2. Apply request values; process events

    3. Process validations; process events

    4. Update model values; process events

    5. Invoke application; process events6. Render response

  • 8/9/2019 JSF Lifecycle

    3/12

  • 8/9/2019 JSF Lifecycle

    4/12

    ` This phase of the lifecycle presents three view instances: new view, initialview, and postback, with each one being handled differently.

    New view: JSF builds the view of the Faces page and wires the event handlersand validators to the components. The view is saved in a FacesContext object.

    Initial view : (The first time a page is loaded), JSF creates an empty view. Theempty view will be populated as the user causes events to occur. From an initialview, JSF advances directly to the render response phase.

    Postback : (the user returns to a page she has previously accessed) the viewcorresponding to the page already exists, so it needs only to be restored. In thiscase, JSF uses the existing view's state information to reconstruct its state. Thenext phase after a postback is apply request values.

  • 8/9/2019 JSF Lifecycle

    5/12

    ` The purpose of the apply request values phase is for eachcomponent to retrieve its current state. The components mustfirst be retrieved or created from the FacesContext object,followed by their values. Component values are typicallyretrieved from the request parameters

    During this phase the default conversion takes place(like if any inputTextis mapped to Integer in the bean). If any conversion fails then errormessage associated with the component is generated and queued onFacesContext. This message will be displayed during the renderresponse phase, along with any validation errors resulting from theprocess validations phase.

    Every input control that has an editable value also has an immediateproperty. If this property is set to true, validation takes place in this phaseinstead of the Process Validations phase.

  • 8/9/2019 JSF Lifecycle

    6/12

    Action sources, like a button or a hyperlink, also have an

    immediate property, and if that property is true, they will fire

    action events during this phase as well.

    During this phase, the decoding code can also add events

    or perform other operations based on the request. Once theaction event has been created, it is added to the

    FacesContext for later processing in the Invoke Application

    phase.

    After this phase is completed, any existing events are

    broadcast to interested listeners.

  • 8/9/2019 JSF Lifecycle

    7/12

    In the Process Validations phase, JSF traverses thecomponent tree and asks each component to make sure itssubmitted value is acceptable. Before validation can occur, the submitted value is

    converted, by using the converter registered for the

    component. If both conversion and validation are successful for all

    components whose values were submitted, the lifecyclecontinues onto the next phase. Otherwise, control will skipto the Render Response phase, complete with validationand conversion error messages.

    Once the components submitted value has been validated,its local value is set based on the converted submittedvalue

  • 8/9/2019 JSF Lifecycle

    8/12

    If the local value has changed, the component also

    generates a value-change event.

    At this point, value-change events (and any other events

    associated with this phase) are fired and consumed by the

    appropriate listeners. These listeners have the option ofoutputting a response directly or jumping directly to the

    Render Response phase.

  • 8/9/2019 JSF Lifecycle

    9/12

    ` The fourth phase of the JSF application lifecycle -- update modelvalues -- updates the actual values of the server-side model --namely, by updating the properties of your backing beans (alsoknown as managed beans). Only bean properties that are boundto a component's value will be updated. Now that we are sure all of the local values of the components are

    updated and valid, and of the correct type, its okay to deal with anyassociated backing beans or model objects.

    Because objects are associated with components through JSF ELexpressions, this is where those expressions are evaluated, andproperties are updated based on the components local value.

    You can see that the value property is the expression"#{helloBean.numControls}". JSF will use this to find an instance of abean stored under the key helloBean, searching each of the servletscopesrequest, session, or application

    Once this phase has completed, the framework will broadcast any eventsto all interested listeners. As always, a listener could jump to the RenderResponse phase or return a response itself.

  • 8/9/2019 JSF Lifecycle

    10/12

    ` At the fifth phase of the lifecycle -- invoke application -- the JSFcontroller invokes the application to handle Form submissions.The component values will have been converted, validated, andapplied to the model objects, so you can now use them toexecute the application's business logic.

    `

    At th

    is ph

    ase, you also get to specify th

    e next logical view for agiven sequence or number of possible sequences. You do this bydefining a specific outcome for a successful form submission andreturning that outcome. For example: on successful outcome,move the user to the next page. For this navigation to work, youwill have to create a mapping to the successful outcome as anavigation rule in the faces-config.xml file. Once the navigation

    occurs, you move to the final phase of the lifecycle.

  • 8/9/2019 JSF Lifecycle

    11/12

    ` In the sixth phase of the lifecycle -- renderresponse -- you display the view with all of itscomponents in their current state.

    ` The secondary goal of this phase is to save thestate of the view so that it can be restored in theRestore View phase if the user requests it again.

    ` During the encoding process for each component,converters are also invoked to translate the

    component values into strings for display

  • 8/9/2019 JSF Lifecycle

    12/12