6.26.  < rich:componentControl >

6.26.1. Description

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

Table 6.88. rich : componentControl attributes

Attribute NameDescription
attachTimingDefines an Id of a component or HTML element listened by the control component
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.
bindingThe attribute takes a value-binding expression for a component property of a backing bean
disableDefaultDisable default action for target event ( append "return false;" to javascript )
eventThe Event that is used to trigger the operation on the target component
forClient identifier of the target component.
idEvery 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.
renderedIf "false", this component is not rendered

Table 6.89. 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

6.26.2. 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.3. Creating the Component Dynamically Using Java

Example:


import org.richfaces.component.html.HtmlComponentControl;   
...
HtmlComponentControl myCalendar = new HtmlComponentControl();
...

6.26.4. Details of Usage

There are three ways to use the <rich:componentControl> to another component.

  • Defining 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 "call" 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) {
}
  • Attaching 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)">
        ...
    </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.

  • Attaching 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> tag. 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.

6.26.5. Look-and-Feel Customization

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

6.26.6. 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.