Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

Registering a Custom Renderer with a Render Kit

For every UI component that a render kit supports, the render kit defines a set of Renderer objects that can render the component in different ways to the client supported by the render kit. For example, the standard UISelectOne component class defines a component that allows a user to select one item from a group of items. This component can be rendered using the Listbox renderer, the Menu renderer, or the Radio renderer. Each renderer produces a different appearance for the component. The Listbox renderer renders a menu that displays all possible values. The Menu renderer renders a subset of all possible values. The Radio renderer renders a set of radio buttons.

When the application developer creates a custom renderer, as described in Delegating Rendering to a Renderer, you must register it using the appropriate render kit. Because the image map application implements an HTML image map, AreaRenderer (as well as MapRenderer) should be registered using the HTML render kit.

You register the renderer using the render-kit element of the application configuration resource file. Here is the configuration of the AreaRenderer from the Duke's Bookstore application:

<render-kit>
  <renderer>
    <renderer-type>DemoArea</renderer-type>
    <renderer-class>
      renderkit.AreaRenderer
    </renderer-class>
    <attribute>
      <attribute-name>onmouseout</attribute-name>
      <attribute-class>java.lang.String</attribute-class>
    </attribute>
    <attribute>
      <attribute-name>onmouseover</attribute-name>
      <attribute-class>java.lang.String</attribute-class>
    </attribute>
    <attribute>
      <attribute-name>styleClass</attribute-name>
      <attribute-class>java.lang.String</attribute-class>
    </attribute>
    <supported-component-class>
      <component-class>
        components.AreaComponent
      </component-class>
    </supported-component-class>
  </renderer>
  ... 

The render-kit element represents a RenderKit implementation. If no render-kit-id is specified, the default HTML render kit is assumed. The renderer element represents a Renderer implementation. By nesting the renderer element inside the render-kit element, you are registering the renderer with the RenderKit associated with the render-kit element.

The renderer-type will be used by the tag handler, as explained in the next section. The renderer-class is the fully qualified class name of the Renderer.

Each of the attribute tags specifies a render-dependent attribute and its type. The attribute element doesn't affect the runtime execution of your application. Instead, it provides information to tools about the attributes the Renderer supports.

The supported-component-class tag specifies the UI component classes that delegate their rendering to this renderer.

Divider
Download
FAQ
History
PrevHomeNext API
Search
Feedback
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.