Newer Version Available

This content describes an older version of this product. View Latest

Custom Component Controllers

Similar to standard Visualforce pages, custom components can be associated with a controller written in Apex. This association is made by setting the controller attribute on the component to your custom controller. You can use the controller to perform additional logic before returning the component's markup to the associated page.

Accessing Custom Component Attributes in a Controller

To access the value of a custom component attribute in an associated custom component controller:
  1. Define a property in the custom component controller to store the value of the attribute.
  2. Define a getter and setter method for the property. For example:
    Notice that the setter modifies the value.
  3. In the <apex:attribute> tag in your component definition, use the assignTo attribute to bind the attribute to the class variable you just defined. For example:
    Note that when using the assignTo attribute, getter and setter methods, or a property with get and set values, must be defined.
  4. Add the component to a page. For example,
The output of the page will look something like the following: Example page.Notice that the Apex controller method changes controllerValue so that it is displayed with uppercase characters.