I feel badly that I haven't had a chance to blog lately, as I have been very busy.
Tuesday, January 19, 2010
Sunday, November 29, 2009
Application.cfc Reference in CFScript for Coldfusion 9
One of Coldfusion 9's features is the ability to define components entirely within CFScript. I was looking around for an example of Application.cfc in CFScript, and I couldn't find it. So I've compiled it for you here. It includes all available methods and application variables. (If you find something I've missed, let me know!)
Notes:
- The ordering of variables and methods matches Adobe's documentation.
- Descriptions are from Adobe.
- Variables are set to CF defaults.
- onRequest, onError, and onMisingTemplate are commented out because they can mess with your application if you don't implement them properly.
- You do not need to enclose this within cfscript tags.
Application.cfc:
/** @title "Application.cfc reference in CFScript for Coldfusion 9" @description "This component includes all Application.cfc methods and variables, set to their default values (if applicable). Please note that default values are not always desirable, and some methods or variables should be modified or removed depending on the situation." @author "Russ S. (http://cfruss.blogspot.com)" @dateCreated "November 29, 2009" @licence "This work is licensed under the Creative Commons Attribution 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA." @hint "You implement methods in Application.cfc to handle ColdFusion application events and set variables in the CFC to configure application characteristics." */ component output="false" { /* **************************** APPLICATION VARIABLES **************************** */ // The application name. If you do not set this variable, or set it to the empty string, your CFC applies to the unnamed application scope, which is the ColdFusion J2EE servlet context. THIS.name = ""; // Life span, as a real number of days, of the application, including all Application scope variables. THIS.applicationTimeout = createTimeSpan(0, 1, 0, 0); // Whether the application supports Client scope variables. THIS.clientManagement = false; // Where Client variables are stored; can be cookie, registry, or the name of a data source. THIS.clientStorage = "registry"; //cookie||registry||datasource // Contains ColdFusion custom tag paths. THIS.customTagPaths = ""; // The Google Maps API key required to embed Google Maps in your web pages. THIS.googleMapKey = ""; // Name of the data source from which the query retrieves data. THIS.datasource = ""; // Whether to store login information in the Cookie scope or the Session scope. THIS.loginStorage = "cookie"; //cookie||session // A structure that contains ColdFusion mappings. Each element in the structure consists of a key and a value. The logical path is the key and the absolute path is the value. THIS.mappings = {}; // Whether to enable validation on cfform fields when the form is submitted. THIS.serverSideFormValidation = true; // Whether the application supports Session scope variables. THIS.sessionManagement = true; // Life span, as a real number of days, of the user session, including all Session variables. THIS.sessionTimeout = createTimeSpan(0, 0, 30, 0); // Whether to send CFID and CFTOKEN cookies to the client browser. THIS.setClientCookies = true; // Whether to set CFID and CFTOKEN cookies for a domain (not just a host). THIS.setDomainCookies = false; // Whether to protect variables from cross-site scripting attacks. THIS.scriptProtect = false; // A Boolean value that specifies whether to add a security prefix in front of the value that a ColdFusion function returns in JSON-format in response to a remote call. THIS.secureJSON = false; // The security prefix to put in front of the value that a ColdFusion function returns in JSON-format in response to a remote call if the secureJSON setting is true. THIS.secureJSONPrefix = ""; // A comma-delimited list of names of files. Tells ColdFusion not to call the onMissingTemplate method if the files are not found. THIS.welcomeFileList = ""; // A struct that contains the following values: server, username, and password.If no value is specified, takes the value in the administrator. THIS.smtpServersettings = {}; // Request timeout. Overrides the default administrator settings. THIS.timeout = 30; // seconds // A list of ip addresses that need debugging. THIS.debugipaddress = ""; // Overrides the default administrator settings. It does not report compile-time exceptions. THIS.enablerobustexception = false; /* ORM variables */ // Specifies whether ORM should be used for the ColdFusion application.Set the value to true to use ORM. The default is false. THIS.ormenabled = false; // The struct that defines all the ORM settings. Documentation: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSED380324-6CBE-47cb-9E5E-26B66ACA9E81.html THIS.ormsettings = {}; // note: THIS.datasource applies to cfquery as well as ORM. It is defined on line 31. /* **************************** APPLICATION METHODS **************************** */ /** @hint "Runs when an application times out or the server is shutting down." @ApplicationScope "The application scope." */ public void function onApplicationEnd(struct ApplicationScope=structNew()) { return; } /** @hint "Runs when ColdFusion receives the first request for a page in the application." */ public boolean function onApplicationStart() { return true; } /** @hint "Intercepts any HTTP or AMF calls to an application based on CFC request." @cfcname "Fully qualified dotted path to the CFC." @method "The name of the method invoked." @args "The arguments (struct) with which the method is invoked." */ public void function onCFCRequest(required string cfcname, required string method, required string args) { return; } /** @hint "Runs when an uncaught exception occurs in the application." @Exception "The ColdFusion Exception object. For information on the structure of this object, see the description of the cfcatch variable in the cfcatch description." @EventName "The name of the event handler that generated the exception. If the error occurs during request processing and you do not implement an onRequest method, EventName is the empty string." note: This method is commented out because it should only be used in special cases */ /* public void function onError(required any Exception, required string EventName) { return; } */ /** @hint "Runs when a request specifies a non-existent CFML page." @TargetPage "The path from the web root to the requested CFML page." note: This method is commented out because it should only be used in special cases */ /* public boolean function onMissingTemplate(required string TargetPage) { return true; } */ /** @hint "Runs when a request starts, after the onRequestStart event handler. If you implement this method, it must explicitly call the requested page to process it." @TargetPage "Path from the web root to the requested page." note: This method is commented out because it should only be used in special cases */ /* public void function onRequest(required string TargetPage) { return; } */ /** @hint "Runs at the end of a request, after all other CFML code." */ public void function onRequestEnd() { return; } /** @hint "Runs when a request starts." @TargetPage "Path from the web root to the requested page." */ public boolean function onRequestStart(required string TargetPage) { return true; } /** @hint "Runs when a session ends." @SessionScope "The Session scope" @ApplicationScope "The Application scope" */ public void function onSessionEnd(required struct SessionScope, struct ApplicationScope=structNew()) { return; } /** @hint "Runs when a session starts." */ public void function onSessionStart() { return; } }
Posted by Russ at 8:15 PM 1 comments
Labels: application, cfcs, cfscript, coldfusion
Wednesday, September 9, 2009
ListToQuery: My first CFLib submission
My first submission to CFLib.org has been approved and posted! Check it out: CFLib.org - listToQuery.
It is super-simple and does exactly what it says. I wrote it because I was working on a project which required a list be converted to a query, and I couldn't find any existing UDFs to do so.
If you find yourself in a similar situation, I highly recommend submitting your solution to CFLib.org. It helps everyone! Plus, it gives you priceless bragging rights.
On a side note: I was working on CouchDB for Coldfusion and ended up spending 3 hours writing a UDF that I planned to submit to CFLib. When I was done, I found EasySocket, which was submitted a week ago and is almost exactly what I wrote! If only I had searched CFLib for "socket" before writing my own UDF. How disappointing...
Posted by Russ at 9:18 PM 0 comments
Labels: coldfusion, functions, open-source
Monday, August 31, 2009
An object-database for Coldfusion
I've been working on an OODB (object-database) for Coldfusion! It uses CouchDB as the data-storage engine and it is Railo compatible. As far as I know, there is no OODB for Coldfusion yet, so this is fairly cutting-edge.
So far I've got the basic CRUD working, and it is WAY cool. Instead of data-mapping by hand or even using CF 9's fancy new ORM (object-relational mapping), you just make your object and go like so:
OODB.save(myObject, 'myObjID');
How simple is that?! When you want to populate an object with saved data, you go like so:
OODB.load(myObject, 'myObjID');
This has the potential to save vast amounts of development time by allowing developers to focus almost entirely on object behavior instead of data-mapping. I think OODB will be really useful for projects that have relatively small data storage needs (blogs, wikis, etc). SQL will probably remain the best choice for large datasets though.
The next big thing I need to do for this project is to make an OODB method to get lists of object IDs based on the data within them. Until then, this code is more cool than it is useful.
If you'd like to check it out, download CouchDB for Coldfusion. You'll find the OODB files in the OODB directory. Don't forget to install CouchDB first! You'll also need to modify document.cfc to get it working.
WARNING: I don't recommend this for real-world use yet: this is beta code running on beta software.
Follow me on Twitter if you'd like to stay up to date on the latest developments.
Special thanks to Mingo Hagen and Sean Corfield for their continued input and support.
Posted by Russ at 5:26 PM 2 comments
Labels: coldfusion, couchdb, oodb