O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required