6.78.  < rich:tabPanel >

6.78.1. Description

A tab panel displaying tabs for grouping content of the panel.

<rich:tabPanel> component

Figure 6.223.  <rich:tabPanel> component


6.78.2. Key Features

  • Skinnable tab panel and child items

  • Disabled/enabled tab options

  • Customizable headers

  • Group any content inside a tab

  • Each tab has a unique name for direct access (e.g. for switching between tabs)

  • Switch methods can be easily customized with attribute to:

    • Server

    • Client

    • AJAX

  • Switch methods can be selected for the whole tab panel and for the each tab separately

Table 6.432. rich : tabPanel attributes

Attribute NameDescription
activeTabClassA CSS class to be applied to an active tab
bindingThe attribute takes a value-binding expression for a component property of a backing bean
contentClassA CSS class for content of a tab panel
contentStyleA CSS style is for the content of a tab panel
converterId of Converter to be used or reference to a Converter
converterMessageA ValueExpression enabled attribute that, if present, will be used as the text of the converter message, replacing any message that comes from the converter
dirDirection indication for text that does not inherit directionality. Valid values are "LTR" (left-to-right) and "RTL" (right-to-left)
disabledTabClassA CSS class to be applied to a disabled tab
headerAlignmentSets tab headers alignment. It can be "left" or "right". "left" is used by default
headerClassA CSS style is for the header of a tab panel.
headerSpacingSets tab headers spacing. It should be a valid size unit expression
heightHeight of a tab panel defined in pixels or in percents
idEvery component may have a unique id that is automatically created if omitted
immediateA flag indicating that this component value must be converted and validated immediately (that is, during Apply Request Values phase), rather than waiting until a Process Validations phase
inactiveTabClassCSS class to be applied to an inactive (but not disabled) tab
labelA localized user presentable name for this component.
langCode describing the language used in the generated markup for this component
onclickHTML: a script expression; a pointer button is clicked
ondblclickHTML: a script expression; a pointer button is double-clicked
onkeydownHTML: a script expression; a key is pressed down
onkeypressHTML: a script expression; a key is pressed and released
onkeyupHTML: a script expression; a key is released
onmousedownHTML: script expression; a pointer button is pressed down
onmousemoveHTML: a script expression; a pointer is moved within
onmouseoutHTML: a script expression; a pointer is moved away
onmouseoverHTML: a script expression; a pointer is moved onto
onmouseupHTML: script expression; a pointer button is released
ontabchangeHTML: a script expression; a tab has been changed
renderedIf "false", this component is not rendered
requiredIf "true", this component is checked for non-empty input
requiredMessageA ValueExpression enabled attribute that, if present, will be used as the text of the validation message for the "required" facility, if the "required" facility is used
selectedTabAttribute defines name of selected tab
styleCSS style(s) is/are to be applied when this component is rendered
styleClassCorresponds to the HTML class attribute
switchTypeTab switch algorithm: "client", "server"(default), "ajax"
tabClassA CSS class to be applied to all tabs
titleAdvisory title information about markup elements generated for this component
validatorMethodBinding pointing at a method that is called during Process Validations phase of the request processing lifecycle, to validate the current value of this component
validatorMessageA ValueExpression enabled attribute that, if present, will be used as the text of the validator message, replacing any message that comes from the validator
valueThe current value of this component
valueChangeListenerListener for value changes
widthWidth of a tab panel defined in pixels or in percents. The default value is 100%

Table 6.433. Component identification parameters

NameValue
component-typeorg.richfaces.tabPanel
component-classorg.richfaces.component.html.HtmltabPanel
component-familyorg.richfaces.tabPanel
renderer-typeorg.richfaces.tabPanelRenderer
tag-classorg.richfaces.taglib.tabPanelTag

6.78.3. Creating the Component with a Page Tag

To create the simplest variant on a page use the following syntax:

Example:


...
    <rich:tabPanel>
        <!--//Set of Tabs inside-->
        <rich:tab>
            ...
        </rich:tab>
    </rich:tabPanel>
...

6.78.4. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.HtmltabPanel;
... 
HtmltabPanel mytabPanel = new HtmltabPanel();
...

6.78.5. Details of Usage

As it was mentioned above, tabPanel groups content on panels and performs switching from one to another. Hence, modes of switching between panels are described first of all.

Note:

All tabPanels should be wrapped into a form element so as content is correctly submitted inside. If a form is placed into each tab, the Action elements of Tab controls appear to be out of the form and content submission inside the panels could be performed only for Action components inside tabs.

Switching mode could be chosen with the tabPanel attribute "mode" with three possible parameters.

  • Server (DEFAULT)

    The common submission is performed around tabPanel and a page is completely rendered on a called panel. Only one at a time tabPanel is uploaded onto the client side.

  • Ajax

    AJAX form submission is performed around the tabPanel, content of the called tabPanel is uploaded on Ajax request and additionally specified elements in the "reRender" attribute are rendered. Only one at a time tabPanel is uploaded on the client.

  • Client

    All tabPanels are uploaded on the client side. The switching from the active to the hidden panel is performed with client JavaScript.

As a result, the tabPanel is switched to the second tab according to the action returning outcome for moving onto another page and switching from the second to the first tab is performed.

There is also the "selectedTab" attribute. The attribute keeps an active tab name; therefore, an active tabPanel could be changed with setting a name of the necessary tab to this attribute.

There is also the "headerAlignment" attribute responsible for rendering of tabPanel components. The attribute has several values: left (Default), right, center, which specify Tabs components location on the top of the tabPanel.

Example:


...
    <rich:tabPanel width="40%" headerAlignment="right">
        <rich:tab label="Canon">
            ...
        </rich:tab>
        <rich:tab label="Nikon">
            ...
        </rich:tab>
        <rich:tab label="Olympus">
            ...
        </rich:tab>
    </rich:tabPanel>
...
<rich:tabPanel> with right aligned tabs

Figure 6.224.  <rich:tabPanel> with right aligned tabs


The "label" attribute is a generic attribute. The "label" attribute provides an association between a component, and the message that the component (indirectly) produced. This attribute defines the parameters of localized error and informational messages that occur as a result of conversion, validation, or other application actions during the request processing lifecycle. With the help of this attribute you can replace the last parameter substitution token shown in the messages. For example, {1} for “DoubleRangeValidator.MAXIMUM”, {2} for “ShortConverter.SHORT”.

Except the specific attributes, the component has all necessary attributes for JavaScript events definition.

  • onmouseover

  • onmouseout

  • etc.

6.78.6. Look-and-Feel Customization

For skinnability implementation, the components use a style class redefinition method. Default style classes are mapped on skin parameters.

There are two ways to redefine the appearance of all <rich:tabPanel> components at once:

  • Redefine the corresponding skin parameters

  • Add to your style sheets style classes used by a <rich:tabPanel> component

6.78.7. Skin Parameters Redefinition

Table 6.434. Skin parameters redefinition for a header

Skin parametersCSS properties
panelBorderColorborder-top-color

Table 6.435. Skin parameters redefinition for an internal content

Skin parametersCSS properties
generalBackgroundColorbackground-color
generalTextColorcolor
panelBorderColorborder-bottom-color
panelBorderColorborder-right-color
panelBorderColorborder-left-color
generalSizeFontfont-size
generalFamilyFontfont-family

6.78.8. Definition of Custom Style Classes

On the screenshot there are classes names that define styles for component elements.

Style classes

Figure 6.225. Style classes


Table 6.436. Classes names that define a component appearance

Class nameDescription
rich-tabpanelDefines styles for all tabPanel
rich-tabpanel-contentDefines styles for an internal content
rich-tabpanel-content-positionDefines styles for a wrapper element of a tabPanel content. It should define a shift equal to borders width in order to overlap panel tabs
rich-tabhdr-side-borderDefines styles for side elements of a tabPanel header
rich-tabhdr-side-cellDefines styles for a header internal element

Table 6.437. Classes names that define different tab header states (corresponds to rich-tabhdr-side-cell)

Class nameDescription
rich-tabhdr-cell-activeDefines styles for an internal element of an active header
rich-tabhdr-cell-inactiveDefines styles for an internal element of an inactive label
rich-tabhdr-cell-disabledDefines styles for an internal element of a disabled label

In order to redefine styles for all <rich:tabPanel> components on a page using CSS, it's enough to create classes with the same names (possible classes could be found in the table above) and define necessary properties in them. An example is placed below:

Example:


...
.rich-tabhdr-cell-active{
    
font-weight: bold;
}
...

This is a result:

Redefinition styles with predefined classes

Figure 6.226. Redefinition styles with predefined classes


In the example a tab active font weight and text color were changed.

Also it’s possible to change styles of particular <rich:tabPanel> component. In this case you should create own style classes and use them in corresponding <rich:tabPanel> styleClass attributes. An example is placed below:

Example:


...
.myClass{
       
font-style: italic;
}
...

The "styleClass" attribute for <rich:tabPanel> is defined as it’s shown in the example below:

Example:


<rich:tabPanel ... activeTabClass="myClass"/>

This is a result:

Redefinition styles with own classes and styleClass attributes

Figure 6.227. Redefinition styles with own classes and styleClass attributes


As it could be seen on the picture above, font style on inactive tab was changed.

6.78.9. Relevant Resources Links

Here you can see the example of <rich:tabPanel> usage and sources for the given example.