Java Reference
In-Depth Information
You do not need to create a custom component in these cases:
• You need to aggregate components to create a new component that has its own
unique behavior. In this situation, you can use a composite component to combine
existing standard components. For more information on composite components,
see “Composite Components” in
The Java EE 6 Tutorial: Basic Concepts
and
• You simply need to manipulate data on the component or add application-specific
functionality to it. In this situation, you should create a managed bean for this pur-
pose and bind it to the standard component rather than create a custom component.
See “Managed Beans in JavaServer Faces Technology” in
The Java EE 6 Tutorial:
Basic Concepts
for more information on managed beans.
• You need to convert a component's data to a type not supported by its renderer. See
“Using the Standard Converters” in
The Java EE 6 Tutorial: Basic Concepts
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” in
The Java EE 6 Tutorial: Basic
Concepts
and “
Creating and Using a Custom Validator
”
on page
128
for more in-
formation about validating a component's data.
• You need to register event listeners on components. You can either register event
listeners on components using the
f:valueChangeListener
and
f:actionListener
tags, or you can point at an event-processing method
on a managed bean using the component's
actionListener
or
valueChangeListener
attributes. See
“
Implementing an Event Listener
”
on
page
117
and “Writing Managed Bean Methods” in
The Java EE 6 Tutorial: Basic
Concepts
for more information.
When to Use a Custom Renderer
A renderer, which generates the markup to display a component on a web page, allows
you to separate the semantics of a component from its appearance. By keeping this sep-
aration, you can support different kinds of client devices with the same kind of authoring
experience. You can think of a renderer as a “client adapter.” It produces output suitable
for consumption and display by the client, and accepts input from the client when the user
interacts with that component.
If you are creating a custom component, you need to ensure, among other things, that your
component class performs these operations that are central to rendering the component: