Upload
piers-bryant
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
Agenda
Quick Intro to ColdFusion Components (CFCs)
CFC Coding Details and Tips
CFC “Issues”
CFC Examples
Q & A
3“Life Through a Browser”
CFCs in a Nutshell
A new way to encapsulate code.
Collection of methods with built in security
Quick and Easy Web Services
Pseudo-Object Oriented (No, it’s not really OO)
New tags: <cfcomponent>, <cfproperty>, <cffunction>, <cfreturn>
4“Life Through a Browser”
CFC Example
<cfcomponent>
<cffunction name="sayHello">
<cfif hour(now()) lt 12>
<cfreturn "Good Morning">
<cfelseif hour(now()) lt 18>
<cfreturn "Good Afternoon">
<cfelse>
<cfreturn "Good Evening">
</cfif>
</cffunction>
</cfcomponent>
5“Life Through a Browser”
CFC Example (2)
<cfinvoke component="simple" method="sayHello" returnVariable="greeting">
<cfoutput>#greeting#</cfoutput>
<p>
<cfset greeter = createObject("component","simple")>
<cfoutput>#greeter.sayHello()#</cfoutput>
6“Life Through a Browser”
CFC Tips: Constructors
CFCs do not have a formal constructor…
However – any code not inside a method is run when the CFC is instantiated (created or called remotely).
Generates white space! Use output=false in <cfcomponent> (also in <cffunction>)
7“Life Through a Browser”
CFC Tips: Let’s Talk about Data
This Accessible to caller code Shows up in dump, but not getMetaData()
Unnamed “private” scope Not accessible to caller code Accessible to children Not like Variables, can’t be dumped. (Fixed in RedSky)
Method arguments
Method temporary variables (var scope)
8“Life Through a Browser”
CFC Methods
Default access is public – change to private
Specify all attributes, even optional ones: access (important for security!) returnType (important for validation!) output (controls white space!) hint roles
9“Life Through a Browser”
CFC Methods (2)
returnType should be one of:
any numeric
array query
binary string
boolean struct
date uuid
guid variableName
Or must be the name of a CFC type Watch out for structure instead of struct,
number instead of numeric, etc.
10“Life Through a Browser”
CFC Methods (3)
Output versus Return
Outputting from the method will not work for Flash Remoting
Use the var scope
This is intentional: Use the var scope Applies to UDFs as well!
11“Life Through a Browser”
<cfproperty> - What does it really do?
It does NOT create variables.
It does NOT validate variables.
It does create entries in the meta data.
It helps define the WSDL returned by a web service
12“Life Through a Browser”
CFC “Issues”
<cfinclude> inside a method will not have access to Arguments
<cftransaction> and CFCs
ArgumentCollection and <cfinvoke>
Cached CFCs lose access to output, other scopes
You can’t duplicate (correctly) or serialize (correctly) a CFC
Undefined arguments show up in arguments struct
13“Life Through a Browser”
Web Services Gotchas…
No optional arguments allowed for methods AXIS limitation
Caching of Arguments Fixed by using CF Admin to refresh the WS
14“Life Through a Browser”
CFC Examples
Session Tracker
Unit Tester (from DRK3)
Nathan Dintenfass’ Descriptor
15“Life Through a Browser”
Questions and Resources
www.cfczone.org
cfcdev mailing list
Macromedia DevNet Articles
http://www.macromedia.com/devnet/mx/coldfusion/cfcs.html
CFDJ Articles