JBoss.org Community Documentation

- Prev
- Next

## 6.26. < rich:componentControl >

### 6.26.1. Description

The <rich:componentControl> allows to call JavaScript API functions on components after defined events.

### 6.26.2. Key Features

- Management of components JavaScript API

- Customizable initialization variants

- Customizable activation events

- Possibility to pass parameters to the target component

Table 6.99. rich : componentControl attributes

Attribute Name | Description
--- | ---
attachTiming | Defines the page loading phase when componentControl is attached to another component. Default value is "onavailable"
attachTo | Client identifier of the component or id of the existing DOM element that is a source for given event. If attachTo is defined, the event is attached on the client according to the AttachTiming attribute. If attachTo is not defined, the event is attached on the server to the closest in the component tree parent component.
binding | The attribute takes a value-binding expression for a component property of a backing bean
disableDefault | Disable default action for target event ( append "return false;" to javascript )
event | The Event that is used to trigger the operation on the target component
for | Client identifier of the target component.
id | Every component may have a unique id that is automatically created if omitted
name | The optional name of the function that might be used to trigger the operation on the target component
operation | The function of Javascript API that will be invoked. The API method is attached to the 'component' property of the root DOM element that represents the target component. The function has two parameters - event and params. See: 'params' attribute for details.
params | The set of parameters passed to the function of Javascript API that will be invoked. The JSON syntax is used to define the parameters, but without open and closed curve bracket. As an alternative, the set of f:param can be used to define the parameters passed to the API function. If both way are used to define the parameters, both set are concatenated. if names are equals, the f:param has a priority.
rendered | If "false", this component is not rendered

Table 6.100. Component identification parameters

Name | Value
--- | ---
component-type | org.richfaces.ComponentControl
component-class | org.richfaces.component.html.HtmlComponentControl
component-family | org.richfaces.ComponentControl
renderer-type | org.richfaces.ComponentControlRenderer
tag-class | org.richfaces.taglib.ComponentControlTag

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

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

Example:

    ...

    <rich:componentControl attachTo="doExpandCalendarID" for="ccCalendarID" event="onclick" operation="Expand" />

    ...

### 6.26.4. Creating the Component Dynamically Using Java

Example:

    import org.richfaces.component.html.HtmlComponentControl;

    ...

    HtmlComponentControl myComponentControl = new HtmlComponentControl();

    ...

### 6.26.5. Details of Usage

In order to use the <rich:componentControl> with another components you need to take the following steps:

- Define a name of a function that is generated (definition is similar to a definition of <a4j:jsFunction> ). An "event" argument is passed to this function.

An example is placed below:

    ...

    <rich:componentControl name="ffunction" for="comp_ID" operation="show"/>

    ...

According to this code a function with name ffunction is generated. It is used in JavaScript code to trigger an operation on the target component with defined id="comp_ID".

The generated function is shown below:

    function ffunction (event) {

    }

- Attach to a parent component (usage is similar to <a4j:support> component).

An example is placed below:

    ...

    <rich:modalPanel id="ccModalPanelID" onshow="alert(event.parameters.show)" onhide="alert(event.parameters.hide)">

        <h:outputText value="#{bean.text}"/>

    </rich:modalPanel>

    <h:commandButton value="Show Modal Panel">

        <rich:componentControl for="ccModalPanelID" event="onclick" disableDefault="true" operation="show">

            <f:param name="show" value="componentControl work(show)"/>

        <rich:componentControl/>

    </h:commandButton>

    ...

In the example the "for" attribute contains value of an id of <rich:modalPanel> component. The "operation" attribute contains a name of JavaScript API function. An "event" attribute is used to trigger an operation defined with the "operation" attribute. A set of parameters is defined with <f:param> . As an alternative, the "params" attribute can be used. Thus, one of main features is that <rich:componentControl> allows to transfer parameters. The "disableDefault" attribute with "true" value is used instead of onclick="return false;" attribute for <h:commandButton> to avoid a problem with form submit and modalPanel showing.

- Attach with "attachTo" attribute.

An example is placed below:

    ...

    <rich:calendar popup="#{componentControl.calendarPopup}" id="ccCalendarID" />

        ...

    <f:verbatim>

        <a href="#" id="doExpandCalendarID">Calendar (nextYear)</a>

    </f:verbatim>

    <rich:componentControl attachTo="doExpandCalendarID" for="ccCalendarID" event="onclick" disableDefault="true" operation="nextYear" />

    ...

In the example the "attachTo" attribute contais a value of an id of <a> element. The "for" attribute contains value of an id of <rich:calendar> component. The "operation" attribute contains a name of JavaScript API function. Thus, clicking on the link represents the next year on the calendar.

With the help of the "attachTiming" attribute you can define the page loading phase when <rich:componentControl> is attached to source component. Possible values are:

- "immediate" - attached during execution of <rich:componentControl> script

- "onavailable" - attached after the target component is initialized

- "onload" - attached after the page is loaded

<rich:componentControl> interacts with such components as: <rich:contextMenu> , <rich:toolTip> , <rich:modalPanel > , <rich:listShuttle> , <rich:orderingList> , <rich:calendar>

In order to use <rich:componentControl> with another component you should place the id of this component into "for" attribute field. All operations with defined component you can find in the JavaScript API section of defined component.

Example:

    ...

    <f:view>

        <h:form>

            <br />

            <rich:toolTip id="toolTipFor" followMouse="false" direction="top-right" mode="ajax" value="This is button" horizontalOffset="5" verticalOffset="5" layout="block" />

        </h:form>

        <h:commandButton id="ButtonID" value="Button">

            <rich:componentControl for="toolTipFor" attachTo="ButtonID" operation="show" event="onclick"/>

        </h:commandButton>

    </f:view>

    ...

This is a result:

Figure 6.22. <rich:toolTip> shows with the help of <rich:componentControl> .

As it could be seen in the picture above, the <rich:toolTip> shows after you click the button.

### 6.26.6. Look-and-Feel Customization

<rich:componentControl> has no skin parameters and custom style classes, as the component isn't visual.

### 6.26.7. Relevant Resources Links

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

Here you can found some additional information about <f:param> component.

- Prev6.25. < rich:comboBox >
- Top of page
- Front page
- Next6.27. < rich:contextMenu >