Send your remarks, comments or wishes to doc team
Subject:
Message:
Your name:
Your email:

JBoss.org Community Documentation

- Prev
- Next

## 6.87. < rich:togglePanel >

### 6.87.1. Description

A wrapper component with named facets, where every facet is shown after activation of the corresponding toggleControl (the other is hidden).

Figure 6.283. <rich:togglePanel> component

### 6.87.2. Key Features

- Support for any content inside

- Three modes of facets switching

  - `Server`

  - `Client`

  - `Ajax`

- Controls for togglePanel can be everywhere in layout

Table 6.519. rich : togglePanel attributes

Attribute Name | Description
--- | ---
binding | The attribute takes a value-binding expression for a component property of a backing bean
converter | Id of Converter to be used or reference to a Converter
converterMessage | A ValueExpression enabled attribute that, if present, will be used as the text of the converter message, replacing any message that comes from the converter
id | Every component may have a unique id that is automatically created if omitted
immediate | A 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
initialState | It contains a name of the first active facet
label | A localized user presentable name for this component.
onclick | HTML: a script expression; a pointer button is clicked
ondblclick | HTML: a script expression; a pointer button is double-clicked
onkeydown | HTML: a script expression; a key is pressed down
onkeypress | HTML: a script expression; a key is pressed and released
onkeyup | HTML: a script expression; a key is released
onmousedown | HTML: script expression; a pointer button is pressed down
onmousemove | HTML: a script expression; a pointer is moved within
onmouseout | HTML: a script expression; a pointer is moved away
onmouseover | HTML: a script expression; a pointer is moved onto
onmouseup | HTML: script expression; a pointer button is released
rendered | If "false", this component is not rendered
required | If "true", this component is checked for non-empty input
requiredMessage | A 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
stateOrder | Names of the facets in the switching order. If ToggleControl doesn't contain information about a next facet to be shown it is switched corresponding to this attribute
style | CSS style(s) is/are to be applied when this component is rendered
styleClass | Corresponds to the HTML class attribute
switchType | Facets switch mode: "client", "server"(default), "ajax".
validator | MethodBinding pointing at a method that is called during Process Validations phase of the request processing lifecycle, to validate the current value of this component
validatorMessage | A ValueExpression enabled attribute that, if present, will be used as the text of the validator message, replacing any message that comes from the validator
value | The current value of this component
valueChangeListener | Listener for value changes

Table 6.520. Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.TogglePanel
component-class | org.richfaces.component.html.HtmlTogglePanel
component-family | org.richfaces.TogglePanel
renderer-type | org.richfaces.TogglePanelRenderer
tag-class | org.richfaces.Taglib.togglePanelTag

### 6.87.3. Creating the Component with a Page Tag

Here is a simple example as it could be used in a page:

Example:

    ...

        <rich:togglePanel>

            <f:facet name="first">

                ...

            </f:facet>

            <f:facet name="second">

                ...

            </f:facet>

                ...

        </rich:togglePanel>

        ...

        <!--//Set of the toggleControls somewhere on a page.-->

    ...

### 6.87.4. Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmltogglePanel;

    ...

    HtmltogglePanel myPanel = new HtmltogglePanel();

    ...

### 6.87.5. Details of Usage

As it was mentioned above, togglePanel splits content into named facets that become rendered and processed when a click performed on controls linked to this togglePanel (either switched on the client or send requests on the server for switching).

The initial component state is defined with "initialState" attribute, where a facet name that is shown at first is defined.

## Note:

It's also possible to define an "empty" facet to implement the functionality as drop-down panels have and make the facet active when no content is required to be rendered.

Switching mode could be defined with the "switchType" attribute with three possible parameters:

- `Server` (DEFAULT)

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

- `Ajax`

  AJAX form submission is performed around the panel, content of the called panel is uploaded on an Ajax request . Only one at a time the panel is uploaded on the client side.

- `Client`

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

"Facets" switching order could be defined on the side of <rich:toggleControl> component or on the panel. On the side of the togglePanel it's possible to define facets switching order with the "stateOrder" attribute. The facets names are enumerated in such an order that they are rendered when a control is clicked, as it's not defined where to switch beforehand.

Example:

    ...

        <rich:togglePanel id="panel" initialState="panelB" switchType="client"

                            stateOrder="panelA,panelB,panelC">

            <f:facet name="panelA">

                ...

            </f:facet>

            <f:facet name="panelB">

                ...

            </f:facet>

            <f:facet name="panelC">

                ...

            </f:facet>

        </rich:togglePanel>

        <rich:toggleControl for="panel" value="Switch"/>

    ...

The example shows a togglePanel initial state when the second facet (`panelB`) is rendered and successive switching from the first to the second happens.

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

### 6.87.6. Look-and-Feel Customization

The component doesn't have its own representation rendering only content of its facets, thus all look and feel is set only for content.

### 6.87.7. Definition of Custom Style Classes

Table 6.521. Classes names that define a component appearance

Class name | Description
--- | ---
rich-toggle-panel | Defines styles for all component
rich-tglctrl | Defines styles for a toggle control

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

Example:

    ...

    .rich-toggle-panel{

        font-style:italic;

    }

    ...

This is a result:

Figure 6.284. Redefinition styles with predefined classes

In the example the font style for output text was changed.

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

Example:

    ...

    .myClass{

        background-color:#bed6f8;

    }

    ...

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

Example:

    <rich:togglePanel ... styleClass="myClass"/>

This is a result:

Figure 6.285. Redefinition styles with own classes and "styleClass" attributes

As it could be seen on the picture above, background color for panel was changed.

### 6.87.8. Relevant Resources Links

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

- Prev6.86. < rich:tab >
- Top of page
- Front page
- Next6.88. < rich:toggleControl >