Using ColdFusion components
231
Note:
To use URL invocation, you must set the
cffunction
tag’s
access
attribute to remote.
To pass parameters to component methods using a URL, append the parameters to the URL in
standard URL query-string, name-value pair syntax; for example:
http://localhost:8500/corpQuery.cfc?method=getEmp&lastName=camden
To pass multiple parameters within a URL, use the ampersand (&) character to delimit the name-
value pairs. For example:
http://localhost:8500/
corpQuerySecure.cfc?method=getAuth&store=women&dept=shoes
Note:
To ensure data security, Macromedia strongly recommends that you not pass sensitive
information over the web using URL strings. Potentially sensitive information includes all personal
user information, including passwords, addresses, telephone numbers, and so on.
If a CFC method that you access using the URL displays output directly, the user’s browser shows
the output. (You can use the
cffunction
tag
output
attribute to disable displaying output.) If
the CFC returns a result using the
cfreturn
tag, ColdFusion converts the text to HTML edit
format (with special characters replaced by their HTML escape sequences), puts it in a WDDX
packet, and includes the packet in the HTML that it returns to the client.
Invoking component methods using a form
To invoke a method using a ColdFusion or HTML form, the following must be true:
•
The
form
or
cfform
tag
action
attribute must specify the CFC filename or path.
•
The form must have an input tag (it can be a hidden input tag) with the name
method
and the
method name as its value.
•
The form must have an input tag for each component method parameter. The
name
attribute
of the tag must be the method parameter name and the field value is the parameter value.
•
The
cffunction
tag that defines the CFC method being invoked must specify the
access="remote"
attribute.
If the CFC method that you invoke from the form displays output directly, the user’s browser
shows the output. (You can use the
cffunction
tag
output
attribute to disable displaying
output.) If the CFC returns a result using the
cfreturn
tag, ColdFusion converts the text to
HTML edit format, puts it in a WDDX packet, and includes the packet in the HTML that it
returns to the client.
To invoke component methods using a form:
1
Create a corpFind.cfm file with the following contents:
<h2>Find People</h2>
<form action="components/corpQuery.cfc" method="post">
<p>Enter employee's last Name:</p>
<input type="Text" name="lastName">
<input type="Hidden" name="method" value="getEmp">
<input type="Submit" title="Submit Query"><br>
</form>
In the example, the
form
tag’s
action
attribute points to the
corpQuery
component. The
input
tags invoke the component method.
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......