In-depth understanding of JSF (2)

Source: Internet
Author: User

Facesservlet, lifecycle, component (Group
Backingbean and JSP are the pillars of the entire JSF framework. The role of component is particularly important. While JSF divides the JSF lifecycle into six stages and divides them into different divisions.
This article comprehensively analyzes the mechanism and process of page processing by JSF from the perspective of JSF lifecycle. In the previous article: [a deep understanding of JSF (1)], we fully introduced JSF. Here, in order to deepen our understanding of JSF, we will review JSF in terms of its webpage processing mechanism and process.

Basically, JSF performs different processing based on different user requests:
1. Page display request: Page initialization. When the page is displayed for the first time (Session unit ).
2. Event Processing request: the user presses the command button or command link and needs to be processed by JSF.

The following sections describe them respectively.

Page Initialization

1. the user requests a JSF page
2. Requests are accepted by the Web server (Servlet/JSP Container) and handled by facesservlet. Service ().
3. Because this is the first time this page is displayed, you can use lifecleimpl. Render to reproduce the screen.
4. Painting
Call jspviewhandlerimpl. renderview when the surface is re-painted.
Requestdispacher. Forward/Redirect calls the compiled JSP code. At this time, if the called JSP has not been compiled or the JSP file has been repaired
If it is changed, the JSP file will be compiled before calling.
5. Execution of JSP code: in JSP, if it is a common HTML Tag and text, it is output directly; for example:
If it is a tag, then
Generate the corresponding instance for the tag, and respectively call Tag. dostarttag/doendtag to draw (generate HTML output ). Of course, in special cases,
For example, H: inputtext, and other JSF tags are basically processed with other JSP
The tag is the same, but the JSF tag is divided into three parts: Tag, component, and Renderer.
Distributed to three parts.
6. Description of JSF tags: As mentioned above, the description of JSF tags is the same as that of common JSP tags. However, JSF tags have a special profile recorder (Renderer). Generally, the following is an illustration of the standard JSF Tag:
Tag. dostarttag
> Component. encodebegin> Renderer. encodebegin> tag
. Encodechildren> component. encodechildren>
Renderer. encodechildren> tag. doendtag> component. encodeend>
Renderer. encodeend
That is to say, the tag and component of the JSF tag only play a calling role, and the real plotting work is completed in the Renderer.
7. Page Initialization is complete. Screen Display.

Button event processing

JSF
Processing events is much more complicated. JSF divides event processing into six phases: restoreview, applyrequestvaluesphase,
Processvalidations, updatemodelvalues,
Invokeapplication, renderview. Each stage completes different processing. The restoreview and renderview
ManagementPage InitializationExactly the same.

The following describes the process of each stage in detail:
1. restoreviewphase (reload view phase ):
As described in, this stage reloads the view structure of the screen. First, try to restore the number of JSF components from the session or cookie. If the view cannot be reloaded, JSF considers the page as the first request of the current user and directly jumps to the renderview (screen re-painting phase) redraw the image.
2. applyrequestvaluesphase (application request value stage ):
In this phase, the data from the browser is mainly reflected in the corresponding components. It can also be viewed as data binding. In addition, this stage also makes a very important process. Event queue processing (queueevent), where the message events added to the queue are processed in 5th stages.
Master
Call process: lifecycle.exe cute ()-> applyrequestvaluesphase.exe cute ()->
Component. processdecodes ()-> component. Decode ()->
Component. valuebinding-> Renderer. Decode ()->
Component. queueevent ()
3. processvalidationsphase (Validity Check phase)
This stage checks the data validity. When an error is detected, the system redirects to the screen redraw stage to redraw the screen.
Master
To call the process: lifecycle.exe cute ()-> processvalidationsphase. Execute ()
->
Uiviewroot. processvalidators ()-> htmlform. processvalidators ()-> uiinput. Validate ()
-> Validators. Validate ()
4. updatemodelvaluesphase (update model value stage ):
In this phase, the component values after conversion (converter transformation, etc.) are reflected in backingbean.
Master
Call process: lifecycle.exe cute ()-> updatemodelvaluesphase.exe cute ()->
Uiviewroot. processupdates-> htmlform. processupdates-> uiinput. processupdates
-> Uiinput. updatemodel-valuebinding (# {beanname. propertyname })
Backingbean
5. invokeapplicationphase (user application processing/event processing phase ):
At this stage, we mainly call the event handling methods of users' applications to process real business logic. It is part of the interface between JSF and user programs.
Master
To call the process: lifecycle.exe cute ()-> invokeapplicationphase.exe cute ()->
> Uiviewroot. processapplication-> htmlcommandbutton. Broadcast-> actionlistenerimpl. processaction
-Methodbinding (# {beanname. methodname}) --> backingbean. eventmethod
6. Render (page re-painting stage): Same as page re-painting process initialized on the page. It is clear that we will not repeat it here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.