Blog

Blog posts made in June 2009
26Jun
2009
ColdFusion Positions In Iraq, KS, and MA

Three ColdFusion positions this week, including one in Iraq:

  • Vykin Corporation (company based in Florida, but position is in Iraq) is looking for a ColdFusion and Flex developer with secret security clearances for the US Department of Defense in Iraq. Requirements include ColdFusion and/or Flex certification. Details posted online.
  • Unnamed client (KS) is looking for a ColdFusion developer for a contract to permanent position. ColdFusion 8 experience required, as is experience with Flash. Contact Melissa Kelly-Foxhoven at recruiter PAiGE Technologies, LLC.
  • NxStage Medical, Inc. (Lawrence, MA) is looking for a ColdFusion developer. Requirements include knowledge of HTML, CSS, JavaScript, XML, and SQL, and a solid understanding of procedural and object-oriented code. Familiarity with framework-driven development environments, and Flash development, a plus. Contact Duane Dumont.

Read More ›

26Jun
2009
Toronto Wraps My Usergroup Presentations

Last night I presented ColdFusion, Flex, and more to a joint meeting of the local Flex and ColdFusion groups. The group took a little while to warm up, but then really got going. The session ran over 2 hours and was highly interactive.

Big winners were spreadsheet integration, ORM, Bolt extensions, and the data connectivity in Flash Builder 4. We also got into a lively and heated tangent conversation about the AS3 server proof-of-concept shown during the MAX sneaks last year (the crowd was lobbying heavily to turn this into a product).

Last night wrapped my scheduled usergroups presentations, for now.

Read More ›

25Jun
2009
Presenting At Usergroup In Toronto Tonight

I am on my way to Toronto for tonight's usergroup presentation on ColdFusion and Flex. Details posted online.

Read More ›

23Jun
2009
Check Out tBlurb.com

Fellow Adobe Platform Evangelist (and recent ColdFusion devotee) Greg Wilson has created tBlurb.com, an app that lets you enter code and get a short URL to it for sharing (you can choose your own or let it pick it for you). The app features a rich text editor, and supports ActionScript, C++, C#, ColdFusion, CSS, Delphi, Java, JavaScript, PHP, Python, Ruby, SQL, VB.NET and XML/HTML. And Greg built it all in ColdFusion!

Read More ›

23Jun
2009
Presenting Tonight At Usergroup In San Francisco

I am in San Francisco for a few days of meetings, video shoots, and more (almost all MAX 2009 related). But tonight I'll get to do what I really enjoy doing, presenting to our usergroups. I'll be presenting ColdFusion and Flash Builder futures to the BACFUG group this evening at 6:30pm in the Adobe San Francisco office (601 Townsend). Details posted online.

Read More ›

22Jun
2009
More On ColdFusion And Spreadsheets

Last week I posted an entry on the spreadsheet support planned for ColdFusion Centaur. That post (unsurprisingly) generated lots of questions and comments, and so I thought it worthwhile to post a bigger and more sophisticated example, this time building a new spreadsheet from scratch.

We'll start with a simple Application.cfc to define the datasource needed for this app:

view plain print about
1<cfcomponent>
2    <cfset this.datasource="cfartgallery">
3</cfcomponent>

Now to create a spreadsheet using a database query:

view plain print about
1<!--- Get data --->
2<cfquery name="ArtOrders">
3SELECT orderid, customerfirstname, customerlastname, total
4FROM orders
5ORDER BY orderid
6</cfquery>
7
8<!--- Save it --->
9<cfspreadsheet action="write"
10    query="ArtOrders"
11    filename="Orders.xls"
12    overwrite="true">

That's all it takes. <cfspreadsheet> creates a spreadsheet populated with the retrieved data, using the query column names as column headers in the first spreadsheet row, and the data starting in the second row. Nice, huh?

But what if you want more control? What if you want to explicitly control data placement? What if you needed to provide row or column or cell level formatting? And what if you needed a total cell containing a formula to SUM the total column?

Here's a complete example:

view plain print about
1<!--- Get data --->
2<cfquery name="ArtOrders">
3SELECT orderid, customerfirstname, customerlastname, total
4FROM orders
5ORDER BY orderid
6</cfquery>
7
8<!--- Create new spreadsheet --->
9<cfset sObj=SpreadsheetNew()>
10
11<!--- Create header row --->
12<cfset SpreadsheetAddRow(sObj, "Order,First Name,Last Name,Amount")>
13<cfset SpreadsheetFormatRow(sObj, {bold=TRUE, alignment="center"}, 1)>
14
15<!--- Add orders from query --->
16<cfset SpreadsheetAddRows(sObj, ArtOrders)>
17
18<!--- Figure out row for formula, 2 after data --->
19<cfset rowDataStart=2>
20<cfset rowDataEnd=ArtOrders.recordCount+1>
21<cfset rowTotal=rowDataEnd+2>
22<cfset totalFormula="SUM(D#rowDataStart#:D#rowDataEnd#)">
23
24<!--- Add total formula --->
25<cfset SpreadsheetSetCellValue(sObj, "TOTAL:", rowTotal, 3)>
26<cfset spreadsheetSetCellFormula(sObj, totalFormula, rowTotal, 4)>
27
28<!--- Format amount column as currency --->    
29<cfset SpreadsheetFormatColumn(sObj, {dataformat="$00000.00"}, 4)>
30
31<!--- Save it --->
32<cfspreadsheet action="write"
33    name="sObj"
34    filename="Orders.xls"
35    overwrite="true">

Once again, we start with a database query. Then, SpreadsheetNew() is used to create a new spreadsheet object.

The code then creates the header row. SpreadsheetAddRow() is used to add a specific row, the column headers (as no row number was specified, SpreadsheetAddRow() adds the row to the next free row, the first). SpreadsheetFormatObject() is then used to format row 1, this function accepts a structure (which here is implicitly created inline).

Next comes the data. SpreadsheetAddRows() adds the entire query to the spreadsheet (again, as no row was specified the data gets added to the next free row).

Now for the formula which will total all orders. So as to not hard code the row, a few <cfset> statements are used to calculate the first and last data row, and the row for the total (2nd row after the end of the data, so leaving one empty row in between data and total). The formula too can't be hard coded, so instead of SUM(D2:D24), the row variables are used to build the formula string dynamically. SpreadsheetSetCellValue() is used to add a title, and SpreadsheetSetCellFormula() inserts the formula.

Next, the entire fourth column, containing the order amounts and the calculated total, is formatted to display as currency using SpreadsheetFormatColumn().

All that is left to do then is to save the file using <cfspreadsheet>.

<cfspreadsheet> and its 30+ supporting functions can do lots more, but this should give you a taste of just what's possible using this innovative new feature.

Read More ›

22Jun
2009
For Now, Avoid Kindle Version of My RegEx Book

My Sams Teach Yourself Regular Expressions in 10 Minutes has proven to be a very popular book, and tens of thousands of developers have used it to get started with Regular Expressions. The book teaches RegEx incrementally, and for each example a block of text is used, and matching text is shaded to clearly demonstrate what the Regular Expression is doing.

Sams Teach Yourself Regular Expressions in 10 Minutes has apparently now been released for the Amazon Kindle. I've not seen the Kindle version yet (as I don't have a Kindle yet), but readers are reporting to me that the Kindle version is missing the shading, making all of the examples rather useless!

I've contacted the publisher about this problem, and hope they'll correct it quickly. But for now, I suggest you avoid the Kindle version of the book, and stick with the print version.

Read More ›

22Jun
2009
Executing Code On Server Startup

ColdFusion can execute code when an application starts and ends, when a session starts and ends, when a request starts and ends, and more. But what if you need to execute code when a server starts up? Granted, this is not a common use case, but when needed, we've had to use onApplicationStart for this, probably doing something like:

view plain print about
1<cfif not IsDefined("SERVER.myVar")>
2...
3</cfif>

ColdFusion Centaur adds the ability to define code to be executed onServerStart.

By default this is a method named onServerStart in server.cfc. But, actually, it can be in any ColdFusion Component, including an Application.cfc. In ColdFusion Administrator you can point to the CFC and method to be invoked, and ColdFusion will execute the code on server start-up before processing any requests.

Read More ›

21Jun
2009
The New ColdFusion LOCAL Scope

ColdFusion developers have long known to ensure that local variables remain local by using the "var" keyword to define them. Here's an example:

view plain print about
1<cffunction name="myFunction">
2    <cfset var mySafeVariable = 1>
3    <cfset myUnsafeVariable = 1>
4</cffunction>

In the above snippet, two variables are created. The first variable uses the var keyword to ensure that the variable is local to the function, and if the same variable name existed elsewhere it won't be overwritten. The second variable does not use var, and as such is not local, and variable conflicts can indeed occur. And so, when creating user defined functions or ColdFusion Component methods, the rule has always been to always prefix local variables with "var".

But what exactly is a var variable? What scope is it in? And how is it accessed using explicit scope notation? The answers to these questions are somewhat unclear, partially because the local var scope is not used like any other ColdFusion scope which is always designated by using a scope prefix (VARIABLES.myVariable, FORM.myVariable, SESSION.mayVariable, etc.).

ColdFusion Centaur simplifies the use of local scopes (without breaking existing code) by explicitly defining a local scope that it intuitively named LOCAL. Here is the same local variable set above, but using the LOCAL scope instead of var:

view plain print about
1<cfset LOCAL.mySafeVariable = 1>

But what if you do indeed use var? Well, it'll just work. Look at the following two <CFSET> statements:

view plain print about
1<cfset local.myVar1=1>
2<cfset var myVar1=1>

Both of these code snippets do the exact same thing. Variables with the var prefix are now automatically defined in the LOCAL scope. So a variable defined as:

view plain print about
1<cfset var mySafeVariable = 1>

can be safely accessed as:

view plain print about
1<cfoutput>#LOCAL.mySafeVariable#</cfoutput>

It's clean, it's simple, it's intuitive, and it's fully backwards compatible. And yes, if you have a variable named "local" it'll still work, the variable will just become LOCAL.local, and as the LOCAL scope is in the default evaluation chain it'll just work.

Oh, one other change. The "var" keyword used to only be supported at the top of functions and methods, so all local variables had to be defined upfront. This limitation has been removed in ColdFusion Centaur (and I actually have mixed feelings about this, but so be it).

Read More ›

20Jun
2009
Look, No Datasource

Look at this code snippet. Notice anything odd about it?

view plain print about
1<cfquery name="Art">
2SELECT *
3FROM art
4ORDER BY ArtName
5</cfquery>

Yep, the <CFQUERY> tag in the above snippet is missing the DATASOURCE attribute. And yet, this code works. Why? Take a look at this Application.cfc file:

view plain print about
1<cfcomponent>
2    <cfset this.datasource="cfartgallery">
3</cfcomponent>

In ColdFusion Centaur you can now specify an application wide default datasource by setting this.datasource in Application.cfc. The specified datasource becomes the default for all <CFQUERY>, <CFSTOREDPROC>, and other tags that expect a datasource to be specified. Of course, datasource can still be specified manually if needed, and a specified datasource will override the application default one.

This is one of those duh! enhancements that just makes sense. And, as I'll explain in an upcoming post, it also has another important purpose.

Read More ›