Download
PDF
Home
History
PrevBeginningNext API
Search
Feedback
FAQ
Divider

Steps for Creating a Custom Component

Before we describe how the image map works, it helps to summarize the basic steps for creating custom components. You can apply the following steps while developing your own custom component.

  1. Write a tag handler class that extends javax.faces.webapp.UIComponentTag. In this class, you need a getRendererType method, which returns the type of your custom renderer if you are using one (explained in step 4); a getComponentType method, which returns the type of the custom component; and a setProperties method, in which you set all the new attributes of your component
  2. Create a tag library descriptor (TLD) that defines the custom tag.
  3. Create a custom component class that
    1. Overrides the getFamily method to return the component family, which is used to look up renderers that can render the component.
    2. Includes the rendering code or delegates it to a renderer (explained in step 4).
    3. Enables value-binding.
    4. Queues an event on the component if the component generates events.
    5. Saves and restores the component state.
  4. Delegate rendering to a renderer if your component does not handle the rendering. To do this:
    1. Create a custom renderer class by extending javax.faces.render.Renderer.
    2. Register the renderer to a render kit.
    3. Identify the renderer type in the component tag handler.
  5. Register the component.
  6. Create an event handler if your component generates events.

The application architect does the work of registering the custom component and the renderer. See Registering a Custom Converter and Registering a Custom Renderer with a Render Kit for more information. Using a Custom Component discusses how to use the custom component in a JavaServer Faces page.

Divider
Download
PDF
Home
History
PrevBeginningNext API
Search
Feedback

FAQ
Divider

All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.