ColdFusion Certification upgrade notes going from CF6 to CF7
Contents:
Part 1: Introduction
Part 2: Basic stuff - mixed bag
Part 3: Application.cfc
Part 4: Form validation
Part 5: New presentation abilities
Part 6: New way to print
Part 7: Reporting capabilities of CF7
Part 8: Custom tags review
Part 9: XML review
Part 10: Event gateways
Part 11: New features only - worthy of a note
1. Introduction
This guide is a set of notes I made while studying for ColdFusion 7
certification exam. At the time these notes were written I was already certified by
Macromedia as ColdFusion 6 Advanced Developer. This guide is concentrating only
on aspects that are different between CF6 and CF7 as well as interesting rare
points. It also covers some legacy stuff (like custom tags) that are part of
the exam but no longer used by developers as much as before - thus many
developers, including myself no longer remember how to create them in detail required by the exam.
Notes provided here are for people that already know ColdFusion. They are
not detailed nor well organized - this is not a book. I only included stuff
that I found interesting or something I didn't known before. Most of this is new ColdFusion 7 (CF7 for short) stuff, like
Application.cfc. I didn't include Application.cfm stuff, since I already know
it well from ColdFusion 6/6.1 (CF6 for short).
Guide version 0.1 last updated on 11/10/2005.
I provide this guide as is, without any guarantees, explicit or implied, as
to its contents. You may use the information contained herein in your computer
career, however I take no responsibility for any damages you may incur as a
result of following this guide. You may use this document freely and share it
with anybody as long as you provide the whole document in one piece and do not
charge any money for it. If you find any mistakes, please feel free to inform
me about them Tom Kitta. Legal stuff aside, let us start.
2. Basic stuff - mixed bag
- Remember that form variables don't have to adhere to CF variable naming rules.
- No need to prefix the following scopes: CLIENT, COOKIE, FORM, URL, CGI, VARIABLES, ARGUMENTS, local function,
query results from cfoutput. CF looks for values in client scope last -
the rest - above list is in the reverse lookup order.
- New types supported like EURODATE, SSN or CREDITCARD - not supported everywhere, supported by cfform child tags and cfparam.
- CF supports logical operators IMP (implication), EQV (equivalency) and XOR (exclusive or).
- In CF "is" is like "===" in Java. I.e. exact equality including check whatever the variable type is the same. ColdFusion will still ignore string case.
- Cfquery returns now the "executionTime" in a special structure that by default is named "cfquery", it can be given different name with the help of "result" attribute.
- Extra info about objects can be extracted with new getMetaData(any_object) method.
- Don't forget about cfinsert and cfupdate tags - they need exact field names to work.
- Cfoutput groups data by specific column *distinct* values when "group" attribute is used.
- Cfparam tag can be used to validate variable type - including all new types (like ssn).
- Cookies are recorded by the browser when requests ends, before request ends they are stored in RAM for
on page use (this is why you cannot use cfflush on the same page).
- Old CF session IDs persist even when browser is closed until timeout occurs. New J2EE ID is wiped out when user closes the
browser (all browser windows created by session storing process need to be closed). Note that when we pass sessions in URL query
string the J2EE ID is called "jsessionid". J2EE sessions can be shared with JSP applications and can work in clusters
when under the control of J2EE servers.
- When using multiple variable scope locks (for example application and session scopes), always lock & unlock in the same sequence in order to avoid a deadlock.
- If structure key string case (i.e. whatever letters are in upper or lower case) is important use
myStruct["key"] syntax not myStruct.key, the later will convert
to all upper case when retrieved by say a web service.
- Don't forget that structure name is just a pointer to memory location - its the reson for the existance of the duplicate() function.
- Since I always forget - queries are structures of arrays (not the other way around) i.e. "myQuery.column[positionInCol]".
- CF7 introduced "horizontalbar" chart format. Charts can also be formatted using XML based skins such as
default, blue, beige, red, silver and yellow located under /charting/styles directory. Pie charts have "_pie" added
to skin name. The use "style" attribute to assign new skin. You may skip the number sign (#) when providing colors, if you want the number sign you need to escape it with another
number sign. A reminder: for drill down charts the detail page can have in its URL query string {someVar}=$value$, {someVar}=$itemlabel$ and {someVar}=$seriesLabel$ (note $).
- Pie charts cannot be combined with other chart types - i.e. multiple series charts don't contain pie charts.
- Multiple record sets returned via cfprocresult require the presence of multiple cfprocresult tags with unique value of "resultSet" attribute in each tag.
- New tag in CF7 - cftimer - used to find out code running time. With attribute "label" set to some description of what is
measured it can show code timings. Before use this tag has to be enabled in CF administrator.
- New performance gathering method, getMetricData() takes "PERF_MONITOR" in windows and
"cfstat" in UNIX. Returns performance structure.
- CF supports functions with unknown number of parameters - just use "arguments" "array" present in every
function (both tag and script based) the "array" is in quotes since isArray() returns false. CF supports passing functions
to functions (since function is just a special variable).
- Function return values don't support extended types such as "ssn" or "eurodate".
- Use cfinvoke with "webservice" attribute and with cfinvokeargument child tags to consume web services.
- When invoking web services with cfobject tag or createObject() function you may use methods
addSOAPRequestHeader() and getSOAPResponseHeader().
- In addition to above two methods, when creating a web service you can use getSOAPrequest() and isSOAPRequest().
- You can create Java, COM, CORBA objects using cfobject tag with attributes: action=create,
type={COM/CORBA/Java}, class={classpath}, name={name as in CF}. Than just
access functions with {name}.{function}. Note that you may need to use JavaCast()
function for passing values to Java methods.
- You can import JSP tag library to CF using cfimport tag with attributes tagLib={your library jar
file path} and prefix= {your name space}. You access JSP tags with
<{name space}:tagname argument=value argument=value ... >.
- Flash can access whole CFM page by connecting to a directory on CF server - CF passes values using
"flash" scope, "flash.result" is sent to Flash application (this is old way to do Flash remoting).
- Collections can be created, repaired and optimized with cfcollection tag. The need to be populated
with cfindex tag, which can also be used to update them (legacy support for optimization). Collections can also be created in the CF administrator. The cfsearch tag is used to
search collections, it returns a query with size limit set at maximum of 64kb. Searches
are case sensitive only if input keyword has mixed case in it. Simple search has built in "stem" operator (search for similar words) with "many"
operator (relevancy score), you may use wildcards, explicit search has to have operators specified. To use external collections you need to specify
"external=yes" in both cfindex and cfsearch tags, only key and score fields will be available.
- When uploading file to the server, form tag has to have attribute "enctype" set to "multipart/form-data". On form
target page cffile has to have action attribute set to "upload".
After upload, by default, returned structure created by cffile tag is called "cffile".
- cfschedule tag can be used to update (update operation is used to create new scheduled events), run and delete tasks. Task pages are executed using http
call - you can execute them by pointing browser to their address.
Scheduler default refresh interval is 15min - i.e. it checks for new tasks every 15min. Task cannot run more often than 60 seconds apart.
- cfmailparam is used to attach files to email messages. You can also use it to attach inline files that
will be used inside email message itself. Additional mail headers are also
set with this tag. You need to specify "server" attribute of cfpop tag in order for CF to know which mail server is the one you want your messages to be retrieved from.
- Email message numbers returned by cfpop tag represent current position of email in the queue and are not unique.
- LDAP is a tree based directory that contains things like (for example) countries, organizations and people.
Each entry is referenced by its "distinguished name" (DN) which
is an address like structure that contains entry name - "relative distinguished name" (RDN) together with entry ancestor entries.
Entries are also divided into classes of objects, referenced using "objectclass" attribute. Use cfldap tag can be used
to query, add, modify and delete LADP directory.
- cfhttp can be used to send files with help of cfhttpparam tag. It can also build queries based on remote data.
- You can create OUTER joins using the WHERE clause by using * (star) as in "where column1*=column2"
to create Left outer join (notice position of the star to the left of the =).
- With the exception of count() aggregate functions ignore NULL values. Count() also ignores nulls if you
specify the column name to count, not a * (star) - which is used to count the number of rows - count(*).
- The attribute "cachedwithin" of cfquery is used to cache data for specific
amount of time while "cachedafter" attribute is used to cache data *after* specific time is reached. Administrator sets the number
of cached queries, can disable them with setting of 0. Unique query is one that has the same SQL and datasource - query name is not important.
- cfswitch takes on expression as input, cfloop "list" and "collection" take expressions as well. In
"collection" loop the "item" attribute contains the name of structure's key.
- For both structures (well known) and arrays (not well known) you don't need to use structNew() and arrayNew() - just start
adding values to a structure or array and CF creates them for you automatically.
- The processing of case statement in cfscript is rather tricky. After CF finds a case match, it will execute matching case
and if there is not "break" keyword found all subsequent cases until either "break" is found or case ends. For
this reason if none of your cases match and you place "defaultcase" at the top of your case statement, without any break,
every case will execute (including default case, which is treated as a match).
- cferror tag "type" attribute value of "validation" is for form fields, no CF tags can be used on error
page, another value, "request" also cannot have on its error page any CF tags. You can use CF tags for
"exception" errors only. Cferror/ onError override global CF administrator error template settings.
3. Application.cfc
- If both Application.cfm and Application.cfc are present, Application.cfc will execute - with new setup there is
no need for OnRequestEnd.cfm.
- In Application.cfc the "this" scope with variables such as "name" is used for
settings that were before in cfapplication tag. For example application name is set as this.name="appName".
- Functions used in Application.cfc (self explanatory except for OnRequest() function call):
- OnApplicationStart - set application variables.
- OnApplicationEnd - is run, for example, at the time server going down (is going to be turned off).
- OnSessionStart - run when session begins.
- OnSessionEnd - runs when session ends (for example timeout).
- OnRequestStart - on page execution start.
- OnRequestEnd - on page execution end.
- OnRequest - executed instead of a webpage - can be used to display maintenance page (it is executed INSTEAD of a web
page!). If present and if you still want to display page requested, you need to explicitly include (cfinclude tag) requested page.
This method cannot be used with web services/ flash remoting.
- OnError - replaces cferror tag attribute "request", two arguments are available to programmer, "exception" and "eventname".
4. Form validation
- The following are important arguments supported by new cfinput tag
- maxlength/Size/value/etc.
- message - text shown when validation fails.
- mask - client side validation only.
- pattern - regular expression validation.
- range - valid range.
- required - true or false.
- validate - multiple data types, including new ones such as "ssn" are supported.
- validateAt - can be one or more of: onBlur (client side), onServer, onSubmit (client side).
- Note that server side validation used by CF is not "secure" it uses hidden form
controls to pass rules. I guess it is intended as a quick hack validation,
since server side validation for most people (including myself) is
understood to be secure (i.e. its our server and we have full control over it).
5. New presentation abilities
- XForms are made of two elements: form definition and XSL form display data (separate content from presentation).
- Skins included for cfform format="XML":
- basic.xsl, basiccss.xsl (no tables).
- beige.xsl, blue.xsl, red.xsl, silver.xsl and bluegray.xsl.
- Your own skins can be "system wide accessible" when they are placed in /cfide/scripts/xsl or application use only -
just use path to the file.
- CF does xsl transformation on the server. No code is generated by CF - it’s just your code
(your xsl and form definitions). Xforms supports DHTML. CF transforms your form code into XML and applies on the server XSL style
sheet to it (does the transformation) and sends results back to the browser as HTML. As a web developer you don't need to know
specific dailect of XML - you only may need to know some XSL - if you don't want to use provided XSL files. Notice that forms
that are intended to use XForms should not contain any formatting in them - it is to be provided by the transformation.
- The following are "extra" controls provided by cfform with format="flash":
- Calendar/datefiled - using cfinput tag attribute "type" with value equal "datefield".
- Data grid - using cfgrid tag.
- Combo box - set with cfselect tag attribute "editable" with value of "true".
- Tree - using cftree tag.
- You should always specify the "width" attribute of the cfform tag - if you don't Flash form will take the whole screen.
- In flash form all elements need unique name attribute, radio controls share same name (its group name).
- cfgrid tag has child tags, cfgridcolumn, cfgridrow and cfgridupdate.
- Note that all html inside cfform with type set to Flash is ignored, to place some formatting use
cfformitem tag with type set to values such as "text" or
"html" - few html tags are supported, like "a", "img" and "br".
- The cfformgroup tag with its type attribute provides ability to group controls and place them visually
on the page, possible values are: accordion, vbox, hbox, vertical, tabnavigator etc.
- cfformgroup tags can be nested, tag with type attribute equal to "page" has to be always nested.
- Forms can have different skins, haloGreen is default, with others haloBlue, haloOrange and
haloSilver. You cannot create your own skins.
- You can format cfform, cfformgroup or each control using "style" attribute which uses
standard CSS - inline styles only.
- Binding is supported by form elements - it is implemented with "bind" attribute of a control. For
example bind="{myName.text}" will copy to the current control
the text value from myName element. Binding source syntax is taken from Flash AS. AS expressions are supported.
- Flash based forms don't support Flash remoting or web services. Flash forms support some AS through the use of
cfformitem tag with attribute "type" equal to "script". You can create new functions that you can
use with your controls (in CF7.01 you can, in CF7 you had to do some hacking with cfsavecontent tag), you can also access some build in Flash functions using AS.
Flash forms don't support "input=file" control (Flash 8 applications support client file upload). If you know AS, you can treat form
elements as flash components version 2 - use same functions to access their properties.
- As of CF 7.01 cfform tag supports "onLoad" action - you can call embeded AS function when form loads in order to
initialize it (pre-populate Flash form). Other supported events are onBlur and onFocus.
- The amount of AS code in your form is limited to 32kb (or 64kb) - same as the size of a class in Flash.
- A greate website for anyone who wants to know more about forms is cfform.com
- Cfslider tag is not supported by Flash forms, but it is still supported by other types of forms.
6. New way to print
- cfdocument tag with format set to PDF or FlashPaper transforms content within it to PDF or Flashpaper
on the fly without the use of cfcontent tag to set MIME type.
- cfdocument supports (or claims to) HTML 4, CSS 1/2, XML 1 and DOM 1/2; it doesn't support JavaScript (or other scripts) and
embedded plugins such as Flash.
- cfdocument has many formatting attributes, it can also write to a file. PDF format may even produce password protected
output for both document user and owner. Encription is supported for PDF output.
- Child tags (that can be nested in cfdocument) are:
- cfdocumentitem - set type to footer, header or pagebreak.
- cfdocumentsection - set different formatting for section of a document, if used all content
must be in sections (stuff not in a section is ignored).
- cfdocument scope exists inside cfdocument tag and has two properties: "currentpagenumber" and "totalpagecount".
7. Reporting capabilities of CF7
- You create .cfr files using report builder, these files are later on processed by build in CF report
parser (single threaded in CF standard, not limited in Enterprise).
- Four report formats are supported, Flashpaper (default format), PDF, RTF (Rich text format - not supported in CF7 but supported in CF7.01) and MS Excel (flashpaper is the default).
- Report builder application is to be installed on a client (Windows only), can be found in CFIDE/installers directory (or downloaded from the web for free).
- For any query related operation you need to enable RDS support on your ColdFusion development server.
- You can embed SQL into .cfr file if you want it to be executed directly (.cfr file without cfreport tag) and for preview during report building. Default SQL can be overwritten
with "query" attribute of cfreport tag to which you pass the variable name that contains new query. New query has to have
field names that the report template expects.
- You can view report directly by pointing to it with a web browser, this can be disabled in report properties.
- You may pass input parameters to your report at runtime using either cfreport tag directly or its child tag, cfreportparam.
Input parameters need to be defined in the report source file (how would you use them if they were not?) and need to be of simple data type.
- You may conditionally exclude report elements using input parameters.
- Sub reports always use embedded SQL (cannot provide one at runtime). They are saved as separate report files.
- You can place charts in reports that use different query than main report query. You can define your own expressions and
functions, you have access to shared scopes. However, your main report is still limited to a single query.
- cfreport tag still supports .rpt files used by Crystal Reports (legacy report system support).
8. Custom tags review
- Custom tags can be placed in the current directory or in tag storage directory which by default is "{cfinstallDir}\customtags" (search in current directory is performed first).
- cfmodule is used to explicitly state custom tag "name" attribute (path to custom tag using dot syntax inside
"customtags" directory) in case of a tag name conflict. You can also use "template" attribute to specify
direct path to any file on the system.
- Inside custom tag values of the attributes passed to it are contained in the "attributes" scope. You need to use
"attributes" prefix.
- The "caller" scope lets you set variables in custom tag calling page from within the custom tag.
- Remember that a "simple" custom tag will run once for tag opening and once for tag closing i.e.
<cf_tom></cf_tom> will execute twice. Use "thisTag" scope variable "executionMode" to find out
whatever you are in tag opening (used for init) or tag closing (processing) modes. ExecutionMode can be "start",
"end" or "inactive" refers to code between custom tags.
- thisTag.hasEndTag is true if tag has closing tag - i.e. tag <cf_tom> has </cf_tom> after it.
- Thistag.generatedContent is used to access (and write to) content present between opening and closing tags - i.e. text
generated during tag's "inactive" mode.
- GetBaseTagList() is a function that returns list of all tags (including tag it is called from) that surround current tag -
all "parents" + itself.
- GetBaseTagData(tag_name) returns a structure with target tag attributes as keys. Used by child tag to get parent tag data.
- cfassociate tag is used to send data from child tags to the parent tag. Attribute
"basetag" has base tag name, while "datacollection" has the name of array of structures placed into thisTag scope of target
parent tag (if not used default name is "assocAttribs"). Note that child tag data array is created in "end" executionMode of
parent tag. Also, this tag should be used in the "start" mode of the child tag (it creates stuff in the "end" mode of specified
parent).
9. XML review
- You convert XML document into XML object using XMLParse(), in CF7 you can validate your XML document against a schema using XMLValidate(xmldoc,validator schema).
- cfxml tag is used to convert text enclosed by it to xml object, xmlNew() is a function that creates blank XML object.
- Don't forget about stuff like xmlroot, xmlchildren[], xmltext etc. You may use structure and array functions on XML objects.
- Assume pXML is your XML object (parsed XML) than "pXML.xmlroot.XmlName" is the tag value of root node.
- "pXML.xmlroot.xmlchildren" is the array of children directly under the root node.
- "pXML.xmlroot.xmlchildren[1].xmlAttributes.myAttribute" is the value of "myAttribute" attribute of the first child tag of the root. Notice counting starts as usual for CF at 1 not 0.
- You can apply XSL stylesheets to your XML documents using XMLtransform(xml[either document or object],xsl,params).
- XMLSearch(xmldoc,xpathstring) is CF implementation of Xpath used for XML document searching - it returns an array of matches.
- WDDX serialization is supported to JS. Note that WDDX is sensitive to < and > outside the packet.
10. Event gateways
- All gateway interaction is done through gateway service, by default this service has request queue
size of 25000 and thread count of 10. Gateways offer asynchronous messaging mechanism that supports Java sockets (TCP/IP), SMS,
XMPP, Java Messaging Service (JMS), asynchronous (background) CF process execution and file systems access.
- Gateways have to be registered in CF admin - gateway name will map to actual Java file (like CFX tags).
- Gateway instances are CF components that connect to particular gateway - there is no limit on the
number of CF components that can use a gateway, but all of these have to be registered in CF (just like gateway names).
- Initiator gateway is one where CF initiates gateway communication/process; for example, CF CFC sends out SMS message.
- Responder gateway is one where gateway execution is initiated by an event, such as receipt of an SMS message.
- The hook for initiator gateway is a function called sendGatewayMessage(gatewayName,messageStruct).
CF template/CFC has to call this function to activate given gateway, for
example, it may send SMS message out. Any page/CFC can do this function call.
- As mentioned before, every gateway has companion CFC, that CFC has to have a function in it called
onIncomingMessage(eventStruct). This method is called when sendGatewayMessage(gateway,dataSent) is called. The "eventStruct" contains some
special pre-defined fields, such as data (struct), gatewayID, originatorID etc.
- onIncomingMessage() method is also called when gateway execution is initiated by an event (responder gateway).
- Note that you may attach configuration file (text) to your gateway that will define different
function to call in companion CFC than the default onIncomingMessage().
You may also have different function called for different types of events accepted by the gateway (or just have a switch in onIncomingMessage()).
- Note that SMS gateway that ships with CF has with it not only the gateway but also SMS server
emulator and device emulator, all things needed for testing & debugging of SMS applications on your development machine.
11. New features only - worthy of a note
- scriptProtect - can be turned on in the cfapplication tag or in the CF Administrator as a global setting.
The feature is a set of regular expressions located in "lib/neo-security.xml" that replaces the tags: object, embed, script,
applet, and meta with the tag "InvalidTag" when they are passed as input to the Form, URL, CGI and COOKIE scopes
- you can pick which ones to check. This is a nice feature but its power should not be overestimated
- CF in-memory query support metadata in queries created with the queryNew function. You can now use variable types assigned to columns (as second argument to "querynew()" function).
Note that since SQL is not typless like CF you may need to use "cast()" function. For string comparison operation
(for example using "like") query of query is case sensitive.
- In CF7 you can directly authenticate users into a MS Windows NT domain using login tags.
- CF7 supports strong encription in encript()/decrypt() functions (like AES).
- Cfchart is now much nicer by default since Flash charts by default feature animations, also you may add your own XML based
skins, default skins are:red, yellow, beige, blue, silver and default.
- You no longer need direct access to CF administrator for common tasks, such as adding new datasource. The archtiecture is made up of a
whole set of CFCs located in "cf_web_root/CFIDE/adminapi" directory. Before you execute any functions you need to login, by
using the "login" function (and passing admin password to it) of "administrator" component.
Please be advised that above notes are highly abridged - they contain information that is either new in CF7 or was already present in version 6 but
was rarely used by me. You are strongly advised to read more about the material covered by CF certification exam. A good start would be to study official exam
preparation guide written by Ben Forta.
If you found some mistakes in these notes or you would like to contribute some of your own work to above notes, feel free to contact the author. You can
use contact information contained on my website.