O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Developing Custom Renderers

Developing a custom renderer is relatively simple. All renderers extend an abstract class called javax.faces.render.Renderer. Subclasses of this class are attached to components and are responsible for rendering (or encoding, as it’s called in the specification) the component and, if it’s an input component, for decoding the submitted value to the component’s internal representation.

A component is equipped with a renderer of a specific type by calling the component’s setRendererType( ) method. The renderer type is an identifier that’s unique per component family. Each component belongs to a component family, which identifies the basic nature of a component, e.g., that it’s an output component or a command component. Which renderer class to use for a component is determined by the combination of the renderer type the component is equipped with and the family it belongs to. Picking a renderer class based on the combination of the two IDs makes it possible to use the same, intuitive renderer type IDs for renderer classes with widely different behavior, each class registered for a different component family. For instance, the renderer type ID javax.faces.Link combined with the javax.faces.Output family can identify a renderer class that renders a regular HTML link element with the component’s value as the URL, and the same renderer type ID combined with the javax.faces.Command family can identify another renderer class that renders an HTML link element ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required