Building ColdFusion components
239
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 variable 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. Which technique
you use should depend on your application’s 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>
The ColdFusion page or other client, such as a Flash application, that receives the result then uses
the variable data as appropriate.
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...