Wednesday, October 26, 2011

Java EE 6 - JavaServer Faces Technology 2.0 - Tutorial Highlights

These are my notes from the Java Tutorial located here.

What Is a JavaServer Faces Application?


The functionality provided by a JavaServer Faces application is similar to that of any other Java web application. A typical JavaServer Faces application includes the following parts:

  • A set of web pages in which components are laid out

  • A set of tags to add components to the web page

  • A set of managed beans, which are lightweight container-managed objects (POJOs) with minimal requirements. They support a small set of basic services, such as resource injection, lifecycle callbacks and interceptors.

  • A web deployment descriptor (web.xml file)

  • Optionally, one or more application configuration resource files, such as a faces-config.xml file, which can be used to define page navigation rules and configure beans and other custom objects, such as custom components

  • Optionally, a set of custom objects, which can include custom components, validators, converters, or listeners, created by the application developer

  • A set of custom tags for representing custom objects on the page


Figure 4-1 shows the interaction between client and server in a typical JavaServer Faces application. In response to a client request, a web page is rendered by the web container that implements JavaServer Faces technology.

The web page, myfacelet.xhtml, is built using JavaServer Faces component tags. Component tags are used to add components to the view (represented by myUI in the diagram), which is the server-side representation of the page. In addition to components, the web page can also reference objects, such as the following:

  • Any event listeners, validators, and converters that are registered on the components

  • The JavaBeans components that capture the data and process the application-specific functionality of the components


On request from the client, the view is rendered as a response. Rendering is the process whereby, based on the server-side view, the web container generates output, such as HTML or XHTML, that can be read by the client, such as a browser.



---------------------------------------------------------------------------------------

Creating a JavaServer Faces Application




Developing a simple JavaServer Faces application typically requires the following tasks:

  • Developing managed beans --
    Components in a page are associated with managed beans that provide application logic.

  • Creating web pages using component tags --
    In a typical Facelets application, web pages are created in XHTML. The example web page, beanhello.xhtml

  • Mapping the FacesServlet instance --
    The final task requires mapping the FacesServlet, which is done through the web deployment descriptor (web.xml). A typical mapping of FacesServlet is as follows:
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>

    The preceding file segment represents part of a typical JavaServer Faces web deployment descriptor. The web deployment descriptor can also contain other content relevant to a JavaServer Faces application configuration, but that information is not covered here.
    Mapping the FacesServlet is automatically done for you if you are using an IDE such as NetBeans IDE.

No comments:

Post a Comment