Java Reference
In-Depth Information
Chapter 6. Creating Custom UI Components and Other
Custom Objects
JavaServer Faces technology offers a basic set of standard, reusable UI components that
enable quick and easy construction of user interfaces for web applications. These compon-
ents mostly map one-to-one to the elements in HTML 4. However, an application often
requires a component that has additional functionality or requires a completely new com-
ponent. JavaServer Faces technology allows extension of standard components to enhance
their functionality or to create custom components. A rich ecosystem of third party com-
ponent libraries is built on this extension capability, but it is beyond the scope of this tutori-
al to examine them. A web search for “JSF Component Libraries” is a good starting point
to learn more about this important aspect of using JavaServer Faces technology.
In addition to extending the functionality of standard components, a component writer
might want to give a page author the ability to change the appearance of the component
on the page or to alter listener behavior. Alternatively, the component writer might want
to render a component to a different kind of client device type, such as a smartphone or a
tablet instead of a desktop computer. Enabled by the flexible JavaServer Faces architecture,
a component writer can separate the definition of the component behavior from its appear-
ance by delegating the rendering of the component to a separate renderer. In this way, a
component writer can define the behavior of a custom component once but create multiple
renderers, each of which defines a different way to render the component to a particular
kind of client device.
A javax.faces.component.UIComponent is a Java class that is responsible for
representing a self-contained piece of the user interface during the request processing life-
cycle. It is intended to represent the meaning of the component; the visual representation of
the component is the responsibility of the javax.faces.render.Renderer . There
can be multiple instances of the same UIComponent class in any given JavaServer Faces
view, just as there can be multiple instances of any Java class in any given Java program.
JavaServer Faces technology provides the ability to create custom components by extend-
ing the UIComponent class, the base class for all standard UI components. A custom
component can be used anywhere an ordinary component can be used, such as within
a composite component. A UIComponent is identified by two names: component-
family specifies the purpose of the component (input or output, for instance), while
component-type indicates the specific purpose of a component, such as a text input
field or a command button.
Search WWH ::




Custom Search