
185
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
<cfif #form.conversionType# is "CtoF">
<cfinvoke component="convertTemp" method="ctof" returnvariable="newtemp"
temp=#form.temperature#>
<cfoutput>#form.temperature# degrees Celsius is #newtemp# degrees
Farenheit.</cfoutput>
<cfelseif #form.conversionType# is "FtoC">
<cfinvoke component="convertTemp" method="ftoc"
returnvariable="newtemp" temp=#form.temperature#>
<cfoutput>#form.temperature# degrees Fahrenheit is #newtemp# degrees
Celsius.</cfoutput>
</cfif>
Reviewing the code
The file processForm.cfm invokes the appropriate component method. The following table describes the code and its
function:
To run the example, display the tempConversion.cfm page in your browser. When you enter a value in the text box of
the form, the value is stored in the
form.temperature
variable. Processing is then performed on the processForm.cfm
page, which refers to the value as
form.temperature
. When you invoke either method, the cfinvoke tag assigns the
value
form.temperature
to
temp
;
temp
is the argument specified in the
cfargument
tag of the appropriate method.
The appropriate method in the
convertTemp
component performs the necessary calculations and returns the new
value as
newtemp
.
For detailed reference information on the
cfargument
tag, see the
CFML Reference
.
Code
Description
<cfif form.conversionType is "CtoF">
Executes the code in the cfif block if the user selected Celsius to Fahrenheit
as the conversion type in the form on the tempConversion.cfm page.
<cfinvoke component="convertTemp"
method="ctof"returnvariable="newtemp"arguments
.temp="#form.temperature#">
Invokes the
ctof
method of the
convertTemp
component, without
creating an instance of the
convertTemp
component. Specifies
newtemp
as the result variable for the method. Assigns the temperature value that the
user entered in the form to the variable
temp
, which is specified in the
cfargument
tag of the
ctof
method. When invoking the
ctof
method,
the
temp
variable is assigned to the Arguments scope. For more information
about variables and scope, see “
CFC variables and scope
” on page
198.
<cfoutput>#form.temperature# degrees Celsius is
#newtemp#
b
degrees Fahrenheit.</cfoutput>
Displays the temperature that the user entered in the form, the text
"degrees Celsius is," the new temperature value that results from the
ctof
method, and the text "degrees Fahrenheit."
<cfelseif #form.conversionType# is "FtoC">
Executes the code in the cfelseif block if the user selected Fahrenheit to
Celsius as the conversion type in the form on the tempConversion.cfm page.
<cfinvoke component="converttemp"
method="ftoc"returnvariable="newtemp"
temp=#form.temperature#>
Invokes the
ftoc
method of the
convertTemp
component, without
creating an instance of the
convertTemp
component. Specifies
newtemp
as the result variable for the method. Assigns the temperature value that the
user entered in the form to the variable
temp
, which is specified in the
cfargument
tag of the
ftoc
method. When invoking the
ftoc
method,
the
temp
variable is assigned to the Arguments scope. For more information
about variables and scope, see “
CFC variables and scope
” on page
198.
<cfoutput>#form.temperature# degrees Fahrenheit
is #newtemp#degrees Celsius.</cfoutput>
Displays the temperature that the user entered in the form, the text
"degrees Fahrenheit is," the new temperature value that results from the
ftoc
method, and the text "degrees Celsius."
</cfif>
Closes the
cfif
block.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...