
The life cycle handles both kinds of requests: initial requests and postbacks. When a user makes an initial request for a page, he or she is requesting the page for the first time. When a user executes a postback, he or she submits the form contained on a page that was previously loaded into the browser as a result of executing an initial request. When the life cycle handles an initial request, it only executes the restore view and render response phases because there is no user input or actions to process. Conversely, when the life cycle handles a postback, it executes all of the phases.
1. Restore View
builds the view root and saves to FacesContext, includes event handlers and validators
if it is the initial reqeust, empty view created and life cycle advances to render response directly.
2. Apply Request Value
component extracts its new value from the request parameters. Type conversion occurs in this phase.
if renderResponse called on FacesContext, skip to the render response phase.
FacesContext.responseComplete can be called, and redirect to a different web app
if immediate set to true, the validation, conversion,events will be processed in the phase.
3. Process Validations
process validators registered on the components. if any error message, the life cycle advances directly to the render response phase.
if FacesContext.renderResponse called, skip to the render response phase
if FacesContext.responseComplete called, redirect to a different web app
4. Update Model value
update component value to manage bean property
similarily for FacesContext.responseComplete
similarily for FacesContext.renderResponse
5. Invoke Application
handle application-level events
similarily for FacesContext.responseComplete
6. Render Response
if JSP pages used, the components will render themselves as the JSP container traverses the tags in the page.
if this is the initial request, the components represented on the page will be added to the component tree as the JSP container executes the page.
本文详细解析了JavaServer Faces (JSF) 的生命周期过程,包括处理初始请求和回发请求的不同阶段。介绍了视图恢复、请求值应用、验证处理、模型更新、应用程序调用及响应渲染等六个关键步骤。
230

被折叠的 条评论
为什么被折叠?



