| ColdFusion 9.0 Resources | cfcomponentDescriptionCreates and defines a component object; encloses functionality that you build in CFML and enclose in cffunction tags. This tag contains one or more cffunction tags that define methods. Code within the body of this tag, other than cffunction tags, is executed when the component is instantiated. A component file has the extension CFC and is stored in any directory of an application. A component method is invoked in the following ways: Syntax<cfcomponent 
    alias = "ActionScript 3 type alias" 
    bindingname = "binding element name" 
    displayname = "string" 
    extends = "component name" 
    hint = "string" 
    implements = "ColdFusion interface" 
    namespace = "default service namespace" 
    output = "no value|no|yes" 
    porttypename = "port type element name" 
    Serializable = "yes|no" 
    serviceaddress = "service URL" 
    serviceportname = "port element name" 
    style = "rpc|document" 
    wsdlfile = "path"> 
    variable declarations 
    <cffunction ...> 
        ... 
    </cffunction>  
     
    <cffunction ...> 
        ... 
    </cffunction>  
</cfcomponent>See alsocfargument, cffunction,cfinterface, cfinvoke,cfinvokeargument,cfobject, cfproperty,cfreturn, IsInstanceOf,Building and Using ColdFusion Components in the Developing ColdFusion Applications HistoryColdFusion 9: Added the serializable attribute. ColdFusion 8: 
 ColdFusion MX 7: 
 ColdFusion MX: Added this tag. Attributes
 UsageIf you specify the extends attribute, the data and methods of the parent component are available to CFC methods as if they were parts of the current component. If the managerCFC component extends the employeeCFC component, and the employeeCFC component has a getEmployeeName method, you can call this method by using the managerCFC, as follows: <cfinvoke component="managerCFC" method="getEmployeeName" returnVariable="managerName" 
    EmployeeID=#EmpID#>This tag requires an end tag. If you specify style="document", ColdFusion publishes the CFC as a document-literal style web service. For more information, see Publishing document-literal style web services in the Developing ColdFusion Applications. CFCs support an onMissingMethod function. By defining an onMissingMethod function in the cfcomponent tag body in the CFC, you can handle calls to methods that are not implemented in the CFC. If an application calls a function that is not defined in the CFC, ColdFusion calls the onMissingMethod function and passes it the requested method’s name and arguments. If you do not define an onMissingMethod function, a call to a method that is not defined in the CFC causes ColdFusion to throw an error that must be handled in the calling code. The onMissingMethod function is useful for several purposes: 
 The onMissingMethod function must have the following format: <cffunction name="onMissingMethod"> 
    <cfargument name="missingMethodName" type="string"> 
    <cfargument name="missingMethodArguments" type="struct"> 
        code to handle call to nonexistent method 
</cffunction>Note:   The argument name for onMissingMethod
must not change. Example<cfcomponent> 
    <cffunction name="getEmp"> 
         <cfquery name="empQuery" datasource="cfdocexamples" > 
             SELECT FIRSTNAME, LASTNAME, EMAIL 
             FROM tblEmployees 
         </cfquery> 
         <cfreturn empQuery> 
    </cffunction> 
 
    <cffunction name="getDept"> 
        <cfquery name="deptQuery" datasource="cfdocexamples" > 
             SELECT * 
             FROM tblDepartments 
         </cfquery> 
         <cfreturn deptQuery> 
    </cffunction> 
</cfcomponent> |