Steps for Creating a Custom Component
Before we describe how the image map works, let's summarize the basic steps for creating custom components. You can apply the following steps while developing your own custom component.
- Create a custom component class that does the following
- Overrides the
getFamily
method to return the component family, which is used to look up renderers that can render the component.- Includes the rendering code or delegates it to a renderer (explained in step 4).
- Enables component attributes to accept expressions.
- Queues an event on the component if the component generates events.
- Saves and restores the component state.
- Delegate rendering to a renderer if your component does not handle the rendering. To do this:
- Register the component.
- Create an event handler if your component generates events.
- Write a tag handler class that extends
javax.faces.webapp.UIComponentELTag
. In this class, you need agetRendererType
method, which returns the type of your custom renderer if you are using one (explained in step 2); agetComponentType
method, which returns the type of the custom component; and asetProperties
method, with which you set all the new attributes of your component- Create a tag library descriptor (TLD) that defines the custom tag.
The application architect does the work of registering the custom component and the renderer. See Registering a Custom Converter (page 462) and Registering a Custom Renderer with a Render Kit (page 466) for more information. Using a Custom Component (page 374) discusses how to use the custom component in a JavaServer Faces page.