Java EE Development Technology Course Week 6 (jsf, facelets)

1、jsf(java sever faces)

  1.1 Definition of jsf:

    jsf is a 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.

  1.2 Main components:

    To represent UI components and manage their state, manipulate events, server-side validation and data transformations; define page navigation; support internationalization and accessibility; provide an extensible API for all features for representing UI components in JSP and Two JSP custom tag libraries that send components to server-side objects.

  1.3 Technical advantages:

    Component-based and event-driven development patterns were introduced, allowing developers to develop web applications in a manner similar to dealing with traditional interfaces. Provides a clear separation of behavior and expression. No special scripting language or markup language is used to connect UI components to the web layer. The JSF technology API is layered directly on top of the Servlet API. Technology provides a rich architecture for managing component state, processing component data, validating user input, and manipulating events.

  1.4 How it works: 

    jsf applications are event-driven. When an event occurs (such as the user clicks a button), the event notification is sent to the server via HTTP. The server uses a special servlet called FacesServlet to handle the notification. Every jsf application in the web container has its own FacesServlet;

Behind the scenes, every jsf request triggers 3 things:

      1.4.1 FacesServlet creates FacesContext (this object contains the ServletContext, ServletRequest, ServletRespons objects passed by the Web container to the service method of FacesServlet, which is mainly to modify this FacesContext in the process)

      1.4.2 FacesServlet gives control to Lifecycle

      1.4.3 Lifecycle processes FacesContext in 6 stages (that is, jsf life cycle process)

  1.5 Lifecycle:

    1.5.1. Rebuild the view: build a component tree, if it is the first rendering, the component tree is reset to the appropriate state; if it is not the first rendering, the component tree is created and jumps to the response phase (JSF's component tree structure is the same as DOM. Yes, but the latter is the client and the former is the server).

    1.5.2. Applying request values: Each component in the tree can extract a new value from the request parameter, store the value locally, and then process all component-related events into the queue. If a component's immediate attribute Set to true, then validation, transformation, and events associated with the component are handled at this stage.

    1.5.3. Process validation: Component values ​​are converted to their corresponding data types. If the conversion fails, this phase continues to complete all remaining converters, validating and running the required checks, but upon completion, jumps to the Render Response phase of the lifecycle. If validation is successful, check the required property on the component. If the property is required and a value is entered in the component, the validator associated with it runs. If the required attribute is required but no value is entered, this phase is completed (all remaining validators will continue to execute), and then the lifecycle jumps to the Render Response phase. If the required attribute flag is false, the validation process will not run regardless of whether there is an input value in the component.

    1.5.4. Updating the model: The local value of the validation component is moved into the model, and the local copy is discarded.

    1.5.5. Invoking Application: Execute application-level logic (eg, event handlers).

    1.5.6. Render Response: Renders the components in the tree. Subsequent requests and the Restore View phase save state information.

 

2、facelets 

  Facelets is a lightweight page declaration language for building JSF (JavaServer Faces) views using HTML styles.

It includes the following features:

  • It uses XHTML to create web pages.
  • In addition to supporting JavaServer Faces and the JSTL tag library, it also supports the Facelets tag library.
  • It supports Expression Language (EL).
  • It is a template that uses components and pages.

advantage

  • It supports code reusability through templates and composite components.
  • It provides functional extensibility of components and other server-side objects through customization.
  • Compile time is faster
  • It validates the expression language at compile time.
  • High-performance rendering capabilities.

JSF (JavaServer Faces) technology supports various tag libraries to add components to web pages. To support the JavaServer Faces tag library mechanism, Facelets use XML namespace declarations.

The following table shows the tag libraries supported by Facelets.

 

Reference link: https://baike.baidu.com/item/jsf/442519?fr=aladdin

     http://www.cnblogs.com/zgq0/p/8849106.html

Guess you like

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