Standard JSF Lifecycle

       JavaServer Faces (JSF) is a standard framework for building Java Web applications. It provides a component-centric approach to user interface (UI) building that simplifies the development of Java server-side applications. Its life cycle is mainly divided into the following stages:

                             

       1) Restore View (Restore View)

       A view represents all the components that make up a particular page. It is saved on the client (usually in a hidden field) or server (usually in the session). According to the view ID (page address) accessed by the request, rebuild the DOM tree of the JSF component. If the JSF page is accessed for the first time, that is, the view ID is not stubbed in memory, then JSF will build the DOM tree of the JSF component in memory. Restoring the view also ensures that the component's value, event listener, validator, or converter associated with the component in the tree, is restored.  

        2) Apply Request Values

        The JSF component obtains its own values ​​in the request, including the local value and the submit value. At the same time, the conversion is processed, the conversion is successful, and the local value (submit conversion result) is updated. Of course, the process is not that simple. The JSF processor has its own set of decoding Process.    

        3) Perform verification

       During the validation phase, JSF traverses the component tree and checks each component to see if each component's submitted value is acceptable. Before validation occurs, the submitted value will first be converted by either the converter registered with the component or the default converter. Validation is then performed directly by the component or delegated to one or more other validators. If the user's input is invalid, an error message will be added to the FacesContext, and the component will be indicated as invalid, and then go to the response phase, displaying the current view, indicating the error message.

        4) Update model values

       If all component local value conversion verifications are successful, JSF will process the associated bean according to EL and update the bean binding value. Here JSF will load the configured background bean according to the EL binding.

        5) Call the application

       Call the registered listener, and then perform event-driven to get the next view. The listener can effectively listen to the various data of the UI component at this time, and the event-driven part, that is, the action, can effectively obtain the updated background bean data. Execute your own business logic.

        6) Render Response

        At this point, the request processing is over, and the response page is rendered according to the navigation rules. Execute sequentially.

        Summary : These 6 phases show the order in which JSF typically handles GUIs. Although this list lists the possible execution order of event processing in each phase, the life cycle of JSF is hardly set in stone. You can modify the execution order by omitting a phase or merging the entire lifecycle. For example, if an invalid request value is copied into a component, the current view will be redisplayed and some stages may not be executed. In this case, you can perform a  FacesContext.responseCompletemethod call that redirects the user to a different page, then forwards it to an appropriate Web resource using the request dispatcher ( FacesContextobtained from the request object). Alternatively, you can call  FacesContext.renderResponseto redisplay the original view.

       JSF has the following events:

       1) Action event: Action Event: common action response

 

          ActionEvent is the most common event. Any command component (button, link, etc., see UICommand) can trigger this event to listen to the response by registering an actionListener. Simply put, the user can trigger a meaningful operation.


       2) Immediate Event: Immediate Event: Processed immediately, does not validate/transform/update model values ​​(ie bean will not save properties)

 

         Immediate events, triggered immediately, in the JSF life cycle, after the recovery attempt is made, the request value is obtained and triggered immediately. Validating, transforming, and updating model values ​​are skipped. Of course, in more cases, you need a backend bean to bind the registered UI component. Don't forget, what's your original purpose for using instant events? ? That is, I just want the program to pay attention to this component and exclude the operation of other components or cascaded components. Scenario: In a single form, use "Check if username exists". Immediate time is often used for instant services at the bean level, with the main purpose of executing actions.

 

       3) Value Change Event: Value Change Event: After selecting UI value change, cascade dispatch. If language is selected in internationalization.

 

       4) Phase event: Phase Event: listen to the JSF life cycle of the response 

       This article refers to the blog post: http://www.doc88.com/p-576886331006.html

                            http://blog.sina.com.cn/s/blog_8d5c998901017n7i.html

                      

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324959138&siteId=291194637
jsf