background image

Creating Custom UI Components

<< The ValueChangeListener | When to Use a Custom Component >>
<< The ValueChangeListener | When to Use a Custom Component >>

Creating Custom UI Components

Creating Custom UI Components
JavaServer Faces technology offers a basic set of standard, reusable UI components that enable
page authors and application developers to quickly and easily construct UIs for web
applications. But often an application requires a component that has additional functionality or
requires a completely new component. JavaServer Faces technology allows a component writer
to extend the standard components to enhance their functionality or create custom
components.
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 the component writer might want to render a component to a different client. Enabled by
the flexible JavaServer Faces architecture, a component writer can separate the definition of the
component behavior from its appearance 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.
As well as providing a means to easily create custom components and renderers, the JavaServer
Faces design also makes it easy to reference them from the page through JSP custom tag library
technology.
This chapter uses the image map custom component from the Duke's Bookstore application
(see
"The Example JavaServer Faces Application" on page 319
) to explain how a component
writer can create simple custom components, custom renderers, and associated custom tags,
and take care of all the other details associated with using the components and renderers in an
application.
If you are creating components intended for use with an IDE such as Sun Java Studio Creator,
you might need to take some extra steps beyond what this chapter details to get your
components to work with the IDE. For information on how to make your custom components
work with Sun Java Studio Creator, see the article Writing Custom Components for Java Studio
Creator Part 1: Developing a Component Library, located at
http://developers.sun.com/
prodtech/javatools/jscreator/reference/techart/2/writing_custom_components.html
.
13
C H A P T E R
1 3
409