Create new RichFaces Documentation Jira issue

This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

6.14.1.  < rich:componentControl > available since 3.0.0

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

Table 6.572. rich : componentControl attributes

Attribute Name Description
attachTimingDefines the page loading phase when componentControl is attached to another component. Default value is "onavailable"
attachToClient 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 JSF: The attribute takes a value-binding expression for a component property of a backing bean
disableDefaultDisable default action for target event. If the attribute is not set, it's made "true" by default if the event oncontextmenu is used and false in all other cases. if the attribute set, its value is used.
eventThe Event that is used to trigger the operation on the target component
forClient identifier of the target component.
id JSF: Every component may have a unique id that is automatically created if omitted
nameThe optional name of the function that might be used to trigger the operation on the target component
operationThe 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.
paramsThe 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 JSF: If "false", this component is not rendered

Table 6.573. Component identification parameters

NameValue
component-typeorg.richfaces.ComponentControl
component-classorg.richfaces.component.html.HtmlComponentControl
component-familyorg.richfaces.ComponentControl
renderer-typeorg.richfaces.ComponentControlRenderer
tag-classorg.richfaces.taglib.ComponentControlTag

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

Example:


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

Example:

import org.richfaces.component.html.HtmlComponentControl;   

...
HtmlComponentControl myComponentControl = new HtmlComponentControl();
...

<rich:componentControl> is a command component, that allows to call JavaScript API function on some defined event. Look at the example:


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

In other words it means "clicking on the component with ID 'doExpandCalendarID', expands the component with ID 'ccCalendarID'". It can be said, that <rich:componentControl> connects two components with the help of JavaScript API function.

Component ID, to wich the event, that invokes JavaScript API function is applied, is defined with "attachTo" attribute (see the exapmle above). If "attachTo" attribute is not defined, the component will be attached to the parent component.

Example:


...
<h:commandButton value="Show Modal Panel">
      <rich:componentControl for="ccModalPanelID" event="onclick" operation="show"/> <!--attached to the commandButton-->
</h:commandButton>
...

On the result page the component is rendered to JavaScript code. This means, that it is possible to invoke the <rich:componentControl> handler operation as usual JavaScript function. This function is called by name, specified in the component "name" attribute. The definition of "name" attribute is shown on the example below:


...
<rich:componentControl name="func" event="onRowClick" for="menu" operation="show" />
...

The generated JavaScript function will look as shown below:

function func (event) {
}

An important <rich:componentControl> feature, is that it allows transferring parameters, with the help of special attribute "params" .

Example:


...
<rich:componentControl name="func" event="onRowClick" for="menu" operation="show" params=#{car.model}"/>
...

The alternative way for parameters transferring uses <f:param> attribute. As the code above, the following code will represent the same functionality.

Example:


...
<rich:componentControl event="onRowClick" for="menu" operation="show">
      <f:param value="#{car.model}" name="model"/>
</rich:componentControl>
...

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:

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


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

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

On RichFaces LiveDemo page you can see an example of <rich:componentControl> usage and sources for the given example.

On RichFaces LiveDemo page you can found some additional information about <f:param> component.