JBoss.org Community Documentation

- Prev
- Next

## 6.82. < rich:toggleControl >

### 6.82.1. Description

A link type control for switching between togglePanel facets. Target Panel is specified with "for" attribute. It can be located inside or outside the togglePanel. As the result of switching between facets previous facet is hidden and another one (specified with "switchToState" or panel "stateOrder" attributes) is shown.

Figure 6.265. <rich:toggleControl> component

### 6.82.2. Key Features

- Highly customizable look and feel

- Can be located anywhere in a page layout

- Switching is provided in the three modes

  - `Server`

  - `Client`

  - `Ajax`

Table 6.454. rich : toggleControl attributes

Attribute Name | Description
--- | ---
accesskey | Access key that, when pressed, transfers focus to this element
action | MethodBinding pointing at the application action to be invoked, if this UIComponent is activated by you, during the Apply Request Values or Invoke Application phase of the request processing lifecycle, depending on the value of the immediate property
actionListener | MethodBinding pointing at method accepting an ActionEvent with return type void
ajaxSingle | Boolean attribute which provides possibility to limit JSF tree processing(decoding, conversion/validation, value applying) to the component which send the request only.
binding | The attribute takes a value-binding expression for a component property of a backing bean
bypassUpdates | If "true", after process validations phase skip updates of model beans an force render response. Can be used for validate components input
data | Serialized (on default with JSON) data passed on the client by a developer on AJAX request. It's accessible via "data.foo" syntax
dir | Direction indication for text that does not inherit directionality. Possible values are "LTR" (left-to-right) and "RTL" (right-to-left).
eventsQueue | Name of requests queue to avoid send next request before complete other from same event. Can be used to reduce number of requests of frequently events (key press, mouse move, etc.)
focus | id of element to set focus after request completed on client side
for | String, which contains id (in the format of a UIComponent.findComponent() call) of the target Toggle Panel.
id | Every component may have a unique id that is automatically created if omitted
ignoreDupResponses | Attribute allows to ignore an Ajax Response produced by a request if the newest 'similar' request is in a queue already. ignoreDupResponses="true" does not cancel the request while it is processed on the server, but just allows to avoid unnecessary updates on the client side if the response isn't actual now
immediate | True means, that the default ActionListener should be executed immediately (i.e. during Apply Request Values phase of the request processing lifecycle), rather than waiting until the Invoke Application phase
lang | Code describing the language used in the generated markup for this component
limitToList | If "true", updates on client side ONLY elements from this 'reRender' property. if "false" (default) updates all rendered by ajax region components
onbeforedomupdate | JavaScript code for call before DOM has been updated on client side
onblur | JavaScript code executed when this element loses focus
onclick | JavaScript code executed when a pointer button is clicked over this element
oncomplete | JavaScript code for call after request completed on client side
ondblclick | JavaScript code executed when a pointer button is double clicked over this element
onfocus | JavaScript code executed when this element receives focus
onkeydown | JavaScript code executed when a key is pressed down over this element
onkeypress | JavaScript code executed when a key is pressed and released over this element
onkeyup | JavaScript code executed when a key is released over this element
onmousedown | JavaScript code executed when a pointer button is pressed down over this element
onmousemove | JavaScript code executed when a pointer button is moved within this element
onmouseout | JavaScript code executed when a pointer button is moved away from this element
onmouseover | JavaScript code executed when a pointer button is moved onto this element
onmouseup | JavaScript code executed when a pointer button is released over this element
panelId | Attribute defines Id for corresponding panel
process | Id['s] (in format of call UIComponent.findComponent()) of components, processed at the phases 2-5 in case of AjaxRequest caused by this component. Can be single id, comma-separated list of Id's, or EL Expression with array or Collection
rendered | If "false", this component is not rendered
requestDelay | Attribute defines the time (in ms.) that the request will be wait in the queue before it is ready to send. When the delay time is over, the request will be sent to the server or removed if the newest 'similar' request is in a queue already
status | ID (in format of call UIComponent.findComponent()) of Request status component
style | CSS style(s) to be applied when this component is rendered
styleClass | Space-separated list of CSS style class(es) to be applied when this element is rendered. This value must be passed through as the "class" attribute on generated markup
switchToState | Contains one of the facets names where target togglePanel is switched to
tabindex | Position of this element in the tabbing order for the current document. This value must be an integer between 0 and 32767
timeout | Response waiting time on a particular request. If a response is not received during this time, the request is aborted
title | Advisory title information about markup elements generated for this component
value | Initial value to set when rendered for the first time

Table 6.455. Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.ToggleControl
component-class | org.richfaces.component.html.HtmlToggleControl
component-family | org.richfaces.ToggleControl
renderer-type | org.richfaces.ToggleControlRenderer
tag-class | org.richfaces.taglib.ToggleControlTag

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

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

Example:

    ...

        <rich:toggleControl for="panel"/>

            ...

            <rich:togglePanel id="panel" stateOrder="[facets order to be switched]">

                <!--//Set of Facets-->

            </rich:togglePanel>

    ...

### 6.82.4. Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmlToggleControl;

    ...

    HtmlToggleControl myControl = new HtmlToggleControl();

    ...

### 6.82.5. Details of Usage

As it was mentioned above, the control could be in any place in layout and linked to a switching panel that is managed with "for" attribute (in the "for" attribute the full component "id" is specified according to naming containers).

The togglePanel could be also switched from the side of the control instead of being strictly defined in "switchOrder" attribute of <rich:togglePanel>.

Example:

    ...

        <rich:togglePanel id="panel" initialState="empty" switchType="client">

            <f:facet name="first">

                <h:panelGroup>

                    <rich:toggleControl for="helloForm:panel" value="Empty" switchToState="empty"/>

                    <rich:toggleControl for="helloForm:panel" value=" Second" switchToState="second"/>

                    ...//Some Content

                </h:panelGroup>

            </f:facet>

        <f:facet name="second">

                <h:panelGroup>

                    <rich:toggleControl for="helloForm:panel" value="Empty" switchToState="empty"/>

                    <rich:toggleControl for="helloForm:panel" value=" first" switchToState="first"/>

                    ...//Some Content

                </h:panelGroup>

            </f:facet>

            <f:facet name="empty">

                <h:panelGroup>

                    <rich:toggleControl for="helloForm:panel" value="first" switchToState="first"/>

                    <rich:toggleControl for="helloForm:panel" value=" second" switchToState="second"/>

                </h:panelGroup>

            </f:facet>

        </rich:togglePanel>

    ...

In this example the switching is performed on facets specified in the "switchToState" attribute.

Information about the "process" attribute usage you can find here.

### 6.82.6. Look-and-Feel Customization

For skinnability implementation, the components use a style class redefinition method.

To redefine the appearance of all <rich:toggleControl> components at once, you should add to your style sheets style class used by a <rich:toggleControl> component.

### 6.82.7. Definition of Custom Style Classes

Table 6.456. Classes names that define a component appearance

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

In order to redefine styles for all <rich:toggleControl> 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-tglctrl {

          font-family: monospace;

    }

    ...

This is a result:

Figure 6.266. Redefinition styles with predefined classes

In the example font family was changed.

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

Example:

    ...

    .myClass {

          font-style: italic;

    }

    ...

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

Example:

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

This is a result:

Figure 6.267. Redefinition styles with own classes and styleClass attributes

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

- Prev6.81. < rich:togglePanel >
- Top of page
- Front page
- Next6.83. < rich:toolBar >