Whenever a JSF application receives a request, it goes through a six-step process called the Request Processing Lifecycle. During this process, JSF restores the requested view, translates the request parameters into component values, validates input, updates your backing beans or model objects, invokes action listeners ,and returns a response to the user.
每个阶段的详细解释:
Table 2.2 JavaServer Faces goes through several phases when it processes a single incoming request.
Phase | Description | Events fired |
Restore View | Finds or creates a tree of components for the selected view. Some components, like HtmlCommandButton, will generate action events (or other types of events) in this phase. | Phase events |
Apply Request Values | Updates the value of the components to equal ones sent in the request, optionally using converters. Adds conversion errors if there is an error. Also generates events from request parameters. | Phase events, data model events, action events |
Process Validations | Asks each component to validate itself (which may include using external validators). Validation error messages may be reported. | Phase events, data model events, value-change events |
Update Model Values | Updates all the values of backing beans or model objects associated with components. Conversion error messages may be reported. | Phase events, data model events, |
Invoke Application | Calls any registered action listeners. The default action listener will also execute action methods referenced by command components (like HtmlCommandButton) and choose the next view to be displayed. | Phase events, action events |
Render Response | Displays the selected view using the current display technology (like JSP). | Phase events |
图示例:
Figure 2.4 The Request Processing Lifecycle. Flows with dotted lines are optional. JSF cycles through several phases as it processes each request. After each phase, event listeners are called. Listeners can either continue as normal, report errors and skip to the Render Response phase, or generate the response themselves.