# Class: BaseComponent

## RichFaces. BaseComponent

#### new BaseComponent(componentId)

Base class for all components. All RichFaces components should use this class as base or another RichFaces class which based on it.

         //Inheritance example:
         (function ($, richfaces, params) {

             // Constructor definition
             richfaces.MyComponent = function(componentId, [options]) {
                 // call constructor of parent class
                 $super.constructor.call(this, componentId, [options]);

                 // call this.attachToDom method to attach component to dom element
                 // its required for the client side API calls
                 // and to clean up after ajax request or page unload:
                 // destroy method will be called if component attached to dom
                 this.attachToDom(componentId);

                 };

                 // define private method
                 var myPrivateMethod = function () {
                 }

                 // Extend component class and add protected methods from parent class to our container
                 richfaces.BaseComponent.extend(richfaces.BaseComponent, richfaces.MyComponent);

                 // define super class link
                 var $super = richfaces.MyComponent.$super;

                 // Add new properties and methods
                 $.extend(richfaces.MyComponent.prototype, (function (params) {
                     return {
                         name:"MyComponent",
                         f:function (){alert("hello"),
                         // destroy method definition for clean up
                         destroy: function () {
                             // clean up code here

                             // call parent's destroy method
                             $super.destroy.call(this);
                         }
                     }
                 };
             })(params));
         })(jQuery, RichFaces);

##### Parameters:

Name | Type | Description
--- | --- | ---
`componentId` | string | component id

Source:
  - richfaces-base-component.js, line 90

### Members

#### name :string

Component name.

##### Type:

- string

Source:
  - richfaces-base-component.js, line 195

### Methods

#### (static) extend() → {object}

Method extends child class prototype with parent prototype and return the object with parent's protected methods

Source:
  - richfaces-base-component.js, line 119

##### Returns:

Type
  object

#### attachToDom(source) → {DOMElement}

Attach component object to DOM element by component id, DOM element or jQuery object and returns the element Its required for the client side API calls and to clean up after ajax request or document unload by calling destroy method

##### Parameters:

Name | Type | Description
--- | --- | ---
`source` | string | DOMElement | jQuery | component id, DOM element or DOM elements wrapped by jQuery

Source:
  - richfaces-base-component.js, line 237

##### Returns:

Type
  DOMElement

#### destroy()

Destroy method. Will be called before remove component from the page

Source:
  - richfaces-base-component.js, line 313

#### detach(source)

Detach component object from DOM element by component id, DOM element or jQuery object

##### Parameters:

Name | Type | Description
--- | --- | ---
`source` | string | DOMElement | jQuery | component id, DOM element or DOM elements wrapped by jQuery

Source:
  - richfaces-base-component.js, line 258

#### getEventElement() → {string}

Method returns element's id for event handlers binding. Event API calls this method when binding by component object as selector was used.

Source:
  - richfaces-base-component.js, line 224

##### Returns:

Type
  string

#### invokeEvent(eventType, element, event, data) → {boolean}

Invokes event on on the DOM element

##### Parameters:

Name | Type | Description
--- | --- | ---
`eventType` | string | event type, e.g. "click"
`element` | DOMElement | DOM element object
`event` | Event | jQuery Event
`data` | Object | additional data used for event handler

Source:
  - richfaces-base-component.js, line 272

##### Returns:

true if an event is successfully invoked

Type
  boolean

#### toString() → {string}

Method for converting object to string

Source:
  - richfaces-base-component.js, line 203

##### Returns:

Type
  string