Java Reference
In-Depth Information
Decoding : Converting the incoming request parameters to the local value of the
component
Encoding : Converting the current local value of the component into the corres-
ponding markup that represents it in the response
The JavaServer Faces specification supports two programming models for handling en-
coding 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 cus-
tom component with different renderers so that you can render the component on differ-
ent clients. If you don't plan to render a particular component on different clients, it may
be simpler to let the component class handle the rendering. However, a separate renderer
enables you to preserve the separation of semantics from appearance. The Duke's Book-
store application separates the renderers from the components, although it renders only to
HTML 4 web browsers.
If you aren't sure whether you will need the flexibility offered by separate renderers but
you want to use the simpler direct-implementation approach, you can actually use both
models. Your component class can include some default rendering code, but it can deleg-
ate rendering to a renderer if there is one.
Component, Renderer, and Tag Combinations
When you create a custom component, you can create a custom renderer to go with it. To
associate the component with the renderer and to reference the component from the page,
you will also need a custom tag.
Although you need to write the custom component and renderer, there is no need to write
code for a custom tag (called a tag handler). If you specify the component and renderer
combination, Facelets creates the tag handler automatically.
In rare situations, you might use a custom renderer with a standard component rather than
a custom component. Or you might use a custom tag without a renderer or a component.
This section gives examples of these situations and summarizes what's required for a cus-
tom component, renderer, and tag.
You would use a custom renderer without a custom component if you wanted to add some
client-side validation on a standard component. You would implement the validation code
with a client-side scripting language, such as JavaScript, and then render the JavaScript
Search WWH ::




Custom Search