background image

When to Use a Custom Renderer

<< When to Use a Custom Component | Component Renderer and Tag Combinations >>
<< When to Use a Custom Component | Component Renderer and Tag Combinations >>

When to Use a Custom Renderer

You do not need to create a custom component in these cases:
You simply need to manipulate data on the component or add application-specific
functionality to it. In this situation, you should create a backing bean for this purpose and
bind it to the standard component rather than create a custom component. See
"Backing
Beans" on page 309
for more information on backing beans.
You need to convert a component's data to a type not supported by its renderer. See
"Using
the Standard Converters" on page 354
for more information about converting a
component's data.
You need to perform validation on the component data. Standard validators and custom
validators can be added to a component by using the validator tags from the page. See
"Using the Standard Validators" on page 361
and
"Creating a Custom Validator" on
page 398
for more information about validating a component's data.
You need to register event listeners on components. You can either register event listeners
on components using the valueChangeListener and actionListener tags, or you can
point at an event-processing method on a backing bean using the component's
actionListener
or valueChangeListener attributes. See
"Implementing an Event
Listener" on page 395
and
"Writing Backing Bean Methods" on page 404
for more
information.
When to Use a Custom Renderer
If you are creating a custom component, you need to ensure, among other things, that your
component class performs these operations:
Decoding
: Converting the incoming request parameters to the local value of the component
Encoding
: Converting the current local value of the component into the corresponding
markup that represents it in the response
The JavaServer Faces specification supports two programming models for handling encoding
and decoding:
Direct implementation
: The component class itself implements the decoding and
encoding.
Delegated implementation
: The component class delegates the implementation of
encoding and decoding to a separate renderer.
By delegating the operations to the renderer, you have the option of associating your custom
component with different renderers so that you can represent the component in different ways
on the page. If you don't plan to render a particular component in different ways, it's simpler to
let the component class handle the rendering.
Determining Whether You Need a Custom Component or Renderer
Chapter 13 · Creating Custom UI Components
411