The UITabLabel Class
With the custom renderer out of
the way,
let’s see how to develop a custom component. The
custom component needed for the tab labels is implemented as a class
named UITabLabel
:
package com.mycompany.jsf.component; import java.util.Iterator; import javax.faces.component.UICommand; import javax.faces.component.UIComponent; import javax.faces.el.MethodBinding; import javax.faces.event.ActionEvent; import javax.faces.event.ActionListener import javax.faces.event.FacesEvent; public class UITabLabel extends UICommand { public static final String COMPONENT_TYPE = "com.mycompany.TabLabel"; public static final String COMPONENT_FAMILY = "javax.faces.Command"; public UITabLabel( ) { super( ); setRendererType("javax.faces.Link"); } public String getFamily( ) { return COMPONENT_FAMILY; }
All JSF components must extend the abstract
UIComponent
class, either directly or indirectly
by extending a subclass. A subclass with default implementations for
all methods is called UIComponentBase
, and all
top-level standard components extend this class instead of
UIComponent
. The custom
UITabLabel
class extends the
UICommand
class because its behavior is the same
as the standard command component with just a few twists.
The COMPONENT_TYPE
and
COMPONENT_FAMILY
constants are not required, but
they are defined by convention in all standard JSF component classes,
so I do the same for the custom component. They hold the component
type and component family identifiers for the component.
The ...
Get JavaServer Faces now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.