With the release of ColdFusion 9 this past week, at MAX, we finally have full parity for cfscript with all of the cf tags. I personally prefer script when writing data access and business logic. For some it might not appear to be the sexiest feature, but I can see it making CFML much more appealing to developers from other languages.

A terrific resource, for ColdFusion developers, has always been Ray Camden's Application.cfc Reference. In giving back (and so Ray doesn't have to type it all this time), I thought I'd write an updated Application.cfc Reference, purely in cfscript. This is only the first draft, so if you find anything that should be corrected/added/removed, please let me know. I show you the code directly below, and include it in the download link at the bottom of this post. (BTW, there is code formatting in the file, it just didn't hold in the post for some reason)

view plain print about
1/*
2 * ===================================================================
3 * COMPONENT/CLASS
4 * Application
5 *
6 * PURPOSE
7 * Defines certain ColdFusion application operating parameters, the
8 * Application.cfc is called on every single ColdFusion request, and
9 * specific methods automatically run, depending upon the order of
10 * events within the application lifecycle. This is an example of
11 * an Application.cfc written in pure cfscript. For a better under-
12 * standing of Application.cfc's properties and methods, please
13 * read the Adobe ColdFusion 9 documentation:
14 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-74fa.html
15 *
16 * AUTHOR
17 * Steve 'Cutter' Blades [C], webDOTadminATcutterscrossingDOTcom
18 *
19 * REVISIONS
20 * ===================================================================
21 * [C 10.07.09]
22 * Initial creation
23 * ===================================================================
24 * @output false
25 */

26component {
27
28 // http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7d39.html#WSc3ff6d0ea77859461172e0811cbec22c24-68e0
29 this.name = "ComponentTest";
30 this.applicationTimeout = createTimespan(0,2,0,0);
31 // this.clientManagement = true|false;
32 // this.clientStorage = "cookie|registry|[dsn]";
33 this.customTagPaths = ExpandPath("/tags");
34 // this.googleMapKey = "[Google Map API key]";
35 this.dataSource = "cfbookclub"; // With this I don't need to include the attribute in my cfquery tags
36 // this.loginStorage = "cookie|session";
37 // this.mappings = {mapping1="loc1",mapping2="loc2"}; /* I haven't tried this syntax yet */
38 this.serverSideFormValidation = false; // this is 'true' by default, but I like to write my own
39 this.sessionManagement = true;
40 this.sessionTimeout = createTimespan(0,0,20,0);
41 this.setClientCookies = true;
42 this.setDomainCookies = true;
43 this.scriptProtect = true;
44 // this.secureJSON = true|false;
45 // this.secureJSONPrefix = "[some couple of characters to prefix all JSON]";
46 // this.welcomeFileList = "[comma delimited list of file names]";
47 // this.smtpServerSettings = {server="10.1.93.15",username="someUserName",password="somePassword"};
48 this.timeout = 3000; // This overrides the CF Admin's request timeout value, in milliseconds
49 // this.debuggingIPAddress = "[List of IP's requiring debugging access]";
50 // this.enableRobustException = true|false;
51
52 /**
53 * FUNCTION onApplicationStart
54 * Runs when an application is first initialized
55 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d48.html
56 * @access public
57 * @returnType boolean
58 * @output false
59 */

60    function onApplicationStart() {
61
62 return true;
63    }
64
65 /**
66 * FUNCTION onApplicationEnd
67 * Runs when the application times out, or when explicitly called
68 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d47.html
69 * @access public
70 * @returnType void
71 * @output false
72 */

73    function onApplicationEnd(required applicationScope) {
74
75    }
76
77 /**
78 * FUNCTION onMissingTemplate
79 * Runs when a (CF) template is called that does not exist
80 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d2a.html
81 * @access public
82 * @returnType boolean
83 * @output false
84 */

85    function onMissingTemplate(required string targetpage) {
86 include "404.cfm"; // not required
87 return true;
88    }
89
90 /**
91 * FUNCTION onRequestStart
92 * Runs at the beginning of a request, prior to the processing of
93 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d41.html
94 * the requested template.
95 * @access public
96 * @returnType boolean
97 * @output false
98 */

99    function onRequestStart(required string thePage) {
100 // The following is not required
101 param name="URL.reload" default="false";
102 if (URL.reload){
103 onSessionEnd(SESSION,APPLICATION);
104 onApplicationEnd(APPLICATION);
105 onApplicationStart();
106 onSessionStart();
107 }
108 // end
109
110 return true;
111    }
112
113 /**
114 * FUNCTION onCFCRequest
115 * New to CF9, this function runs only at the beginning of a CFC request
116 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe821657cd7d6f83f6daaa733122cf6931bb-8000.html
117 * @access public
118 * @returnType void
119 * @output false
120 */

121    function onCFCRequest(required string cfcname,required string method,required struct args) {
122
123    }
124
125 /**
126 * FUNCTION onRequest
127 * This runs after the onRequestStart, but still prior to the requested
128 * template itself. This method no longer applys to CFC requests
129 * (see onCFCRequest() for more information)
130 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d43.html
131 * @access public
132 * @returnType void
133 * @output true
134 */

135    function onRequest(required string thePage) {
136
137 include ARGUMENTS.thePage; // When using this method, you must include the requested page
138    }
139
140 /**
141 * FUNCTION onRequestEnd
142 * Runs after a requested template has completed it's process
143 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d42.html
144 * @access public
145 * @returnType void
146 * @output false
147 */

148    function onRequestEnd(required string thePage) {
149
150    }
151
152 /**
153 * FUNCTION onError
154 * This is an application wide error handler. Best practice would be to
155 * write process specific error handling, but this method will help
156 * you trap unexpected errors for custom notification and process
157 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d4a.html
158 * @access public
159 * @returnType void
160 * @output true
161 */

162    function onError(required exception,required string eventname) {
163 writeDump({var=ARGUMENTS.exception,label=ARGUMENTS.eventname}); // not required
164    }
165
166 /**
167 * FUNCTION onSessionStart
168 * Runs when a user first starts there visit to your application.
169 * The application will initialize if it's not currently active
170 * [through onApplicationStart()]. This method would also run
171 * prior to onRequestStart().
172 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d4b.html
173 * @access public
174 * @returnType void
175 * @output false
176 */

177    function onSessionStart() {
178
179    }
180
181 /**
182 * FUNCTION onSessionEnd
183 * Runs when a user's session times out, or when explicitly called
184 * http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d40.html
185 * @access public
186 * @returnType void
187 * @output false
188 */

189    function onSessionEnd(required struct sessionScope,required struct appScope) {
190
191    }
192
193}

There you go! Enjoy! Stay tuned, as I have more ColdFusion 9 goodies on the way...