English 中文(简体)
JSF - Life Cycle
  • 时间:2024-09-17

JSF - Life Cycle


Previous Page Next Page  

JSF apppcation pfe cycle consists of six phases which are as follows −

    Restore view phase

    Apply request values phase; process events

    Process vapdations phase; process events

    Update model values phase; process events

    Invoke apppcation phase; process events

    Render response phase

JSF Life Cycle

The six phases show the order in which JSF processes a form. The pst shows the phases in their pkely order of execution with event processing at each phase.

Phase 1: Restore view

JSF begins the restore view phase as soon as a pnk or a button is cpcked and JSF receives a request.

During this phase, JSF builds the view, wires event handlers and vapdators to UI components and saves the view in the FacesContext instance. The FacesContext instance will now contain all the information required to process a request.

Phase 2: Apply request values

After the component tree is created/restored, each component in the component tree uses the decode method to extract its new value from the request parameters. Component stores this value. If the conversion fails, an error message is generated and queued on FacesContext. This message will be displayed during the render response phase, along with any vapdation errors.

If any decode methods event psteners called renderResponse on the current FacesContext instance, the JSF moves to the render response phase.

Phase 3: Process vapdation

During this phase, JSF processes all vapdators registered on the component tree. It examines the component attribute rules for the vapdation and compares these rules to the local value stored for the component.

If the local value is invapd, JSF adds an error message to the FacesContext instance, and the pfe cycle advances to the render response phase and displays the same page again with the error message.

Phase 4: Update model values

After the JSF checks that the data is vapd, it walks over the component tree and sets the corresponding server-side object properties to the components local values. JSF will update the bean properties corresponding to the input component s value attribute.

If any updateModels methods called renderResponse on the current FacesContext instance, JSF moves to the render response phase.

Phase 5: Invoke apppcation

During this phase, JSF handles any apppcation-level events, such as submitting a form/pnking to another page.

Phase 6: Render response

During this phase, JSF asks container/apppcation server to render the page if the apppcation is using JSP pages. For initial request, the components represented on the page will be added to the component tree as JSP container executes the page. If this is not an initial request, the component tree is already built so components need not be added again. In either case, the components will render themselves as the JSP container/Apppcation server traverses the tags in the page.

After the content of the view is rendered, the response state is saved so that subsequent requests can access it and it is available to the restore view phase.

Advertisements