User Guide

Table Of Contents
Creating ColdFusion components 213
In the example, the cfargument attributes specify the following:
The name attributes define the parameter names.
The type attribute for the lastName argument specifies that the parameter must be a text
string. The
type attribute for the cost argument specifies that the parameter must be a
numeric value. These attributes validate the data before it is submitted to the database.
The required attributes indicate that the parameters are required or an exception will be
thrown.
The Arguments scope provides access to the parameter values.
Providing results
ColdFusion components can provide information in the following ways:
They can generate output that is displayed on the calling page.
They can return a variable.
You can use either technique, or a combination of both, in your applications. The technique that
you use should depend on your applications needs and your coding methodologies. For example,
many CFC methods that perform business logic return the results as a variable, and many CFC
methods that display output directly are designed as modular units for generating output, and do
not do business logic.
Displaying output
If you do not specifically suppress output, any text, HTML code, or output that CFML tags
generate inside your method gets returned as generated output to the client that calls the
component method. If the client is a web browser, it displays these results. For example, the
following
getLocalTime1 component method shows the local time directly on the page that
invokes the method:
<cfcomponent>
<cffunction name="getLocalTime1">
<cfoutput>#TimeFormat(now())#</cfoutput>
</cffunction>
</cfcomponent>
Component methods that are called using Flash Remoting or as web services cannot use this
method to provide results.
Returning a results variable
In the component method definition, you use the
cfreturn tag to return the results to the client
as variable data. For example, the following
getLocalTime2 component method returns the local
time as a variable to the ColdFusion page or other client that invokes the method:
<cfcomponent>
<cffunction name="getLocalTime">
<cfreturn TimeFormat(now())>
</cffunction>
</cfcomponent>