Introducing the JSF Application Programming Interface (API) - Java
This chapter has been leading us gently through the JavaServer Faces technology. More importantly, in it, Budi teaches ushow to write an online survey application to get a feel for how this great technology works. This chapter prepares you for the next chapters by introducing the JSF Application Programming Interface (API) and the Application Configuration file. This excerpt comes from chapter two of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983-7, 2004).
The JSF implementation consists of various interfaces and classes that you can use to write event listeners, validators, custom components, and so on. These interfaces and classes are grouped into the following packages:
javax.faces
javax.faces.application
javax.faces.component
javax.faces.context
javax.faces.convert
javax.faces.el
javax.faces.event
javax.faces.lifecycle
javax.faces.render
javax.faces.tree
javax.faces.validator
javax.faces.webapp
Each package is briefly described in the following sections. Bear in mind that this is only a general introduction to the classes and interfaces in the packages. You will get more details about using these packages in the upcoming chapters, which discuss specific topics related to the classes and interfaces.
The javax.faces Package The javax.faces package contains the FactoryFinder and FacesException classes. The FactoryFinder is responsible for discovering all factory objects specified in the JSF API. An example of a factory object is the javax.faces.context.FacesContextFactory object, which is responsible for creating FacesContext instances. You probably will never need to use the FactoryFinder class during your career as a JSF programmer.
On the other hand, the FacesException class, which is a subclass of java.lang. RuntimeException, encapsulates general JSF exceptions. You will often need to throw an instance of this class in your JSF classes.
The javax.faces.application Package The javax.faces.application package contains important classes such as Action, NavigationHandler, and Application, as well as the Message interface. The Action class represents an object that performs a task and can return a String. The NavigationHandler class handles page navigation.
The Application class represents a per-Web-application singleton object to which JSF can register objects that provide functionality required by JSF. As an example, the default NavigationHandler object that manages page navigation is registered with the Application object.
The Message interface represents a validation or other message. For example, a validator will add a Message object to the FacesContext if the validation of the local value of a component fails. The javax.faces.application.MessageImpl class is the concrete implementation of the Message interface.
The javax.faces.component Package The javax.faces.component package provides interfaces and classes that represent the standard UI components in JSF. The most notable member of this package is the UIComponent interface, which every UI component must implement. A convenience base class that implements this interface is UIComponentBase. Then there are other classes that represent UI components, such as UIForm, UICommand, UIGraphic, UIInput, UIOutput, UIPanel, and UISelectItem. These components are discussed in Chapters 4 and 5.
The javax.faces.context Package The javax.faces.context package contains classes and interfaces that define per-request state information. The FacesContext class represents all of the per-request state information that is needed by the Lifecycle object during the request processing lifecycle. A FacesContext contains many other important objects, such as the component tree and the ExternalContext class.
The ExternalContext class, also a member of this package, is there so that JSF does not need to depend on any particular container. Thanks to this class, JSF can run in either a servlet or a portlet. In a servlet environment, you can get information contained in the ServletContext, ServletRequest, and ServletResponse objects through the instance of ExternalContext.
Other important members of this package are FacesContextFactory and MessageResources. FacesContextFactory is responsible for the creation of FacesContext objects. The MessageResources class represents a collection of message templates that help in constructing localized messages. Chapter 11 discusses how you can achieve internationalization and localization of your JSF applications.
Remember: This is part three of the second chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). If you've enjoyed what you've seen here, click on the "Buy it now!" banner to pick up a copy today! Buy this book!