background image

The UIComponentBase

<< Creating Custom Component Classes | Specifying the Component Family >>
<< Creating Custom Component Classes | Specifying the Component Family >>

The UIComponentBase

If your component extends UIComponentBase, it automatically implements only StateHolder.
Because all components directly or indirectly extend UIComponentBase, they all implement
StateHolder
.
If your component extends one of the other standard components, it might also implement
other behavioral interfaces in addition to StateHolder. If your component extends UICommand,
it automatically implements ActionSource2. If your component extends UIOutput or one of
the component classes that extend UIOutput, it automatically implements ValueHolder. If your
component extends UIInput, it automatically implements EditableValueHolder and
ValueHolder
. See the JavaServer Faces API Javadoc to find out what the other component
classes implement.
You can also make your component explicitly implement a behavioral interface that it doesn't
already by virtue of extending a particular standard component. For example, if you have a
component that extends UIInput and you want it to fire action events, you must make it
explicitly implement ActionSource2 because a UIInput component doesn't automatically
implement this interface.
The image map example has two component classes: AreaComponent and MapComponent. The
MapComponent
class extends UICommand and therefore implements ActionSource2, which
means it can fire action events when a user clicks on the map. The AreaComponent class extends
the standard component UIOutput.
The MapComponent class represents the component corresponding to the map tag:
<bookstore:map id=
"worldMap" current="NAmericas"
immediate=
"true"
action=
"bookstore"
actionListener=
"#{localeBean.chooseLocaleFromMap}">
The AreaComponent class represents the component corresponding to the area tag:
<bookstore:area id=
"NAmerica" value="#{NA}"
onmouseover=
"/template/world_namer.jpg"
onmouseout=
"/template/world.jpg"
targetImage=
"mapImage" />
MapComponent
has one or more AreaComponent instances as children. Its behavior consists of
the following
Retrieving the value of the currently selected area
Defining the properties corresponding to the component's values
Generating an event when the user clicks on the image map
Queuing the event
Saving its state
Rendering the map tag and the input tag
Creating Custom Component Classes
The Java EE 5 Tutorial · September 2007
420