User Guide

Table Of Contents
226 Chapter 10: Building and Using ColdFusion Components
The following example passes the Form scope to the addUser method of the UserDataCFC
component. In the method, each form field name is a parameter name; the method can use the
contents of the form fields to add a user to a database.
<cfinvoke component="UserDataCFC" method="addUser"
argumentCollection="#Form#">
Passing parameters using the cfinvokeargument tag
To pass parameters in the
cfinvoke tag body, use the cfinvokeargument tag. Using the
cfinvokeargument tag, for example, you can build conditional processing that passes a different
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 tag passes the lastName parameter to the component method.
In the following example, a form already let the user select the report to generate. After
instantiating the
getdata and reports components, the action page invokes the doquery
component instance, which returns the query results in
queryall. The action page then invokes
the
doreport component instance and uses the cfinvokeargument tag to pass the query results
to the
doreport instance, where the output is generated.
<cfobject component="getdata" name="doquery">
<cfobject component="reports" name="doreport">
<cfinvoke component="#doquery#" method="#form.whichreport#"
returnvariable="queryall">
<cfinvoke component="#doreport#"method="#form.whichreport#">
<cfinvokeargument name="queryall" value="#queryall#">
</cfinvoke>
Passing parameters in direct method invocations
ColdFusion provides three methods for passing parameters to CFC methods in direct method
invocations:
You can pass the parameters the form of comma-separated name="value" entries, as in the
following CFScript example:
authorized = securityCFC.getAuth(name="Almonzo", Password="LauRa123");
You can pass the parameters in an argumentCollection structure. The following code is
equivalent to the previous example:
argsColl = structNew();
argsColl.username = "Amonzo";
argsColl.password = "LauRa123;
authorized = securityCFC.getAuth(argumentCollection = argsColl);