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.
To access the value of a custom component attribute in an associated custom component controller:
-
Define a property in the custom component controller to store the value of the attribute.
-
Define a getter and setter method for the property. For example:
Notice that the setter modifies the value.
-
In the
<apex:attribute>tag in your component definition, use theassignToattribute to bind the attribute to the class variable you just defined. For example:Note that when using the
assignToattribute, getter and setter methods, or a property withgetandsetvalues, must be defined. -
Add the component to a page. For example,
The output of the page will look something like the following:

Notice that the Apex controller method changes controllerValue so that it is displayed with uppercase characters.