Before starting work with JSF (Java Server Faces), the most important thing to understand is JSF request life cycle process. JSF request starts when a user request for a page and ends with rendering the response page. JSF life cycle consist six main phases to complete a request. All these six phases runs in a sequence, but some phases can be skipped based on some specific situations like conversation error, validation error etc. I will explain each phase in details.
- Restore view phase
- Apply request values phase
- Process validations phase
- Update model values phase
- Invoke application phase
- Render response phase
Apply request values - In apply request value phase all values received from request parameters are converted and stored in corresponding UI components. All values are stored locally. This process is called decoding.
Update model values phase - After validation completed now in update model value phase conversion triggered that will convert the UI component values and set the values in corresponding backing bean properties. If any error occurred during this phase directly render response phase will be called with error message.
Invoke application phase - Now this is the phase where actual user requested task performed. In this phase application events are handled and actual managed beans methods are executed.
Render response phase - This is always the final phase of JSF request life cycle. Outcome will be based on different situations.
So, this is all about JSF request life cycle.
Below is the detailed explanations of each phase.
JSF controller receives the request and check if view is already present for requested page in faces context than use the same otherwise creates a new view for the page, register the event handlers, validators and saves the view in faces context.
If request is initial than an empty view is created returned back to user directly via render response phase. All other phases are skipped.
If request is not initial, controller uses the view objects saved in faces context and continues for the next phase.
If some error occurred during conversion of parameter, an error message is generated and stored in faces context. All further phases will be skipped and directly go to render response phase with error message.
If immediate attribute is set true for some component than conversion, validation and events of that components are processed in this phase. I will explain immediate in more details in next section.
Process validations phase - After apply request values phase all values are locally set in UI components. Now in process validation phase every components value is validated against configured validators. JSF provides a lot of inbuilt validators for Dates, Numbers and String. We can create our custom validators also.
If any validation fails, validation error message is generated and queued in faces context. All further phases will be skipped and directly go to render response phase with error message.
If no error in this phase all backing bean properties are updated with latest vales and life cycles goes to next phase.
After method execution controller decide the outcome page for the request.
If request is initial a new empty page will be rendered.
If page is already in view and values of components are updated than the page will be re-rendered.
If any conversion or validation error occurred than page will be re-rendered with error messages.
I will write more on immediate attribute and JSF validators in next sections.
_________________________________________________
***********************Keep studying***********************
No comments:
Post a Comment