Using Components Directly In Cfscript And Cfml - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

Passing parameters using the cfinvokeargument tag
To pass parameters in the
cfinvokeargument
parameter based on user input.
The following example invokes the corpQuery component:
<cfinvoke component="corpQuery" method="getEmp">
<cfinvokeargument name="lastName" value="Wilder">
</cfinvoke>
The
cfinvokeargument
Invoking methods using dynamic method names
The
tag is the only way to efficiently invoke different component methods based on
cfinvoke
variable data; for example, form input. In this case, you use a variable name, such as
Form.method, as the value of the
<cfinvoke component="corpQuery" method="#Form.queryType#">

Using components directly in CFScript and CFML

You can invoke methods of a component instance directly using CFScript or in CFML tags. After
you instantiate a component, you can invoke the component methods any place that you can use
ColdFusion functions.
You can also access data in the component's This scope directly in CFScript and
assignment statements. For example, if a User data CFC has a This.lastUpdated property, you
could have code such as the following:
<cfobject name="userDataCFC" component="userData">
<cfif DateDiff("d", userDataCFC.lastUpdated, Now()) GT 30>
<!--- code to deal with older data here --->
</cfif>
For more information, see
Invoking component methods directly
To invoke component methods directly, use the
instantiate the component. Thereafter, use the instance name followed by a period and the
method you are calling to invoke an instance methods. You must always use parentheses after the
method name, even if the method does not take any parameters.
You can use this syntax anywhere that you can use a ColdFusion function, such as in
or surrounded by pound (#) signs in the body of a
Invoking component methods in CFScript
The following example shows how to invoke component methods in CFScript:
<!--- instantiate once and reuse the instance--->
<cfscript>
tellTimeCFC=createObject("component","tellTime");
writeOutput("Server's Local Time: " & tellTimeCFC.getLocalTime());
writeOutput("<br> Calculated UTC Time: " & tellTimeCFC.getUTCTime());
</cfscript>
tag body, use the
cfinvoke
tag, for example, you can build conditional processing that passes a different
tag passes the
lastName
attribute, as the following example shows:
method
"The This scope" on page
cfinvokeargument
parameter to the component method.
242.
function or
CreateObject
tag.
cfoutput
Using ColdFusion components
tag. Using the
cfset
tag to
cfobject
tags
cfset
229

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents