“Zeus, There It Is” or “Don’t Bring Me Down…Zeus”

Posted: January 18th, 2012 | Author: | Filed under: ColdFusion | 2 Comments »

I’ll be participating on a preview of ColdFusion Zeus tomorrow at noon. See you there.


ColdFusion 10

Posted: October 5th, 2011 | Author: | Filed under: ColdFusion | No Comments »

Welcome to what may quite possibly be my laziest blog post ever…in which I mention the new version of ColdFusion in the title and simply state that “I’m seeing some juicy details on the new version of ColdFusion…head over to Nathan Struz‘s twitter feed now for more”. Enjoy.


Entity Drive

Posted: September 6th, 2011 | Author: | Filed under: ColdFusion | No Comments »

Imagine if you could define the relationships between entities in your data-driven system once, and then have them automatically link to both the database and to the display pages of your ColdFusion-based system. I’m exploring this concept now and am calling it “Entity Drive”.

The Point
The high-level goal here is to speed up the process of developing software. Every system that I’ve coded shares similar features. Entity Drive automates the process of some of those features…in particular getting data from the database, displaying it (either in list or tree forms) and presenting users with system interactions. I should also point out that the code is easy read, implement and modify.

Concepts

Entity Drive is similar to existing Object-relational mapping (ORM) solutions in that it links the database to system objects. Unlike ORM the code uses a structure in place of objects. I chose a structure or structures in place of objects as I want this to work as fast as possible. This structure is called the Entity Definition.

Each Entity Definition includes four basic pieces:

  1. it’s name
  2. how it relates to the database
  3. how it relates to child entities
  4. which (if any) links to create

From the Entity Definition you simply pass in ancestor and descendent entity names and generate an Entity Chain. An Entity Chain is a slice of the Entity Definition that only contains relevant segments of the Entity Definition. It is limited to definitions of the ancestor entity, the descendent entity and each entity between.

The Entity Chain serves two purposes. The first is to generate queries. The second is to generate views. Both are dynamically generated, which is a fancy way of saying that they are created when and where you need them.

Where I’m At

It works and it’s fast. I have the following features working:

  • Entity Definition created from an XML file
  • Entity Chain created from Entity Definition
  • queries are dynamically generated
  • a basic Tree View feature that outputs the query

What’s Next

  1. refine Tree View feature to restore the tree’s expand/collapse state when a user returns to the page
  2. highlight relevant tree node when user returns
  3. refactor Entity Drive, Entity Chain and Entity DAO objects, adding lots and lots of comments
  4. create unit tests and functional tests for all features
  5. perform testing with a mega-huge data set
  6. create an awesome List View page
  7. documentation, documentation, documentation

In the coming weeks/months I’ll be posting updates and code samples. When it’s done I’ll share it.


ColdFusion 8 Structure Blues

Posted: September 6th, 2011 | Author: | Filed under: ColdFusion | 2 Comments »

I ran across the following error when attempting to add an array to a structure: “Complex object types cannot be converted to simple values”

<cfscript>
request.anArray = ArrayNew(1);
request.aStruct = StructNew();
request.aStructure = request.xml.entity.xmlAttributes;
request.aStructure.aString = "must...drink...coffee...";
 
// interestingly enough this does not throw an error
request.aStructure.aStruct = request.aStruct;
 
// boo hoo, an error :(
request.aStructure.anArray = request.anArray;
</cfscript>

It’s important to note that I am copying structure elements from an xml node. When I remove the reference to xmlAttributes the error vanishes.

<cfscript>
request.anArray = ArrayNew(1);
request.aStruct = StructNew();
request.aStructure = StructNew();
request.aStructure.aString = "must...drink...coffee...";
request.aStructure.aStruct = request.aStruct;
 
// no error this time.  hmm...
request.aStructure.anArray = request.anArray;
</cfscript>

Since I needed to get values from xml I was still up against the error. After a few moments of scratching my head I wrapped the xml in ColdFusion’s Duplicate() method.

<cfscript>
request.anArray = ArrayNew(1);
request.aStruct = StructNew();
 
// booya
request.aStructure = Duplicate(request.xml.entity.xmlAttributes);
 
request.aStructure.aString = "must...drink...coffee...";
request.aStructure.aStruct = request.aStruct;
request.aStructure.anArray = request.anArray;
</cfscript>

ColdFusion’s Duplicate() function to the rescue! The above code does not throw an error, and I am able to get the xml values that I need as well as add arrays to the structure.

I am left wondering if this is a bug in ColdFusion 8. It would appear so to me. At some point I will test this in ColdFusion 9 to see if I get the same results.


Dreamweaver HTML Protyping FTW

Posted: August 18th, 2011 | Author: | Filed under: ColdFusion, jQuery | 1 Comment »

Most ColdFusion developers are using either ColdFusion Builder or Eclipse (with added CFEclipse awesomeness). I’m presently using CFEclipse for ColdFusion development, but when I have to create HTML prototypes I use Adobe Dreamweaver. This morning I leveraged Dreamweaver’s templates and jQuery code completion features to get an ajax-powered, interactive prototype up and running in an hour.

I’m wondering why the folks at Adobe didn’t just add some of ColdFusion Builder’s awesome features to Dreamweaver.


CFEclipse Snippet: Get and Set Methods

Posted: August 17th, 2011 | Author: | Filed under: ColdFusion | No Comments »

Is this really my first post since June?! At any rate here’s a simple tip that may save some of you some time. Here is a CFEclipse Snippet for quickly writing get and set methods.

<!---	get$${Uppercase Property Name} --->
<cffunction name="get$${Uppercase Property Name}" 
	output="false" 
	access="public" 
	returntype="$${Return Type:any|void|string|numeric|struct|array|query}" 
	hint="get method for $${Lowercase Property Name}">
 
	<cfreturn variables.$${Lowercase Property Name} />
</cffunction>
 
<!---	set$${Uppercase Property Name} --->
<cffunction 
	name="set$${Uppercase Property Name}" 
	output="false" 
	access="public" 
	returntype="void" 
	hint="set method for $${Lowercase Property Name}">
 
	<cfargument name="$${Lowercase Property Name}" 
			type="$${Return Type:any|void|string|numeric|struct|array|query}" 
			required="true" 
			hint="set method for $${Lowercase Property Name}" />
 
	<cfset variables.$${Lowercase Property Name} = arguments.$${Lowercase Property Name} />
</cffunction>

How I got started in ColdFusion

Posted: August 3rd, 2011 | Author: | Filed under: ColdFusion, I'm Just Sayin' | No Comments »

I’ve been enjoying reading the “How I got Started in ColdFusion” posts that have been popping up on the interwebs over the last few days.  Here’s my story…

10 PRINT “YOU SMELL” 20 GOTO 10 RUN

By the age of ten I had written my first bit of code on a Timex Sinclair. I copied the basic code for a clock out of the book and from that moment on I was hooked. By 7th grade I was fortunate enough to get a Commodore 128. I wrote a few games (again in basic), and played a LOT of games on that machine. I took basic programming and computer animation classes in high school and enjoyed working with the Commodore Amiga.

Webcrawler and Pentiums

A few years after graduating high school and slacking about I landed a job in the shipping/receiving department at a local computer reseller. At that job I was exposed to x86 and Sun platforms.  I also built my first pc…a totlly bad-ass 133mhz Pentium with 24mb of ram and a 14.4kb modem.  I was the first one in the shop running Windows 95 (no more irq headaches!) and distinctly remember the day that I first saw Netscape 2 in action.

I took to HTML programming and spent countless hours/days/weeks of my free time working on my personal site as well as a site for my band.

Fast forward a few years 1998…the dawn of broadband. I got a job as an field technician at a nationwide DSL provider and spent my free time developing Flash-based interactive training modules for my team. During this time I met quite a few software developers, most of which were having DSL installed in their homes so they could work from home.  the very thought of working from home was a new concept…and one that appealed to me.

<cf_lucky>

As luck would have it I had fixed a dsl circuit at a software development firm about a month before the bottom dropped out of the telecom market. They were impressed with my ability to fix the circuit where others had failed, as well as by the cheesy Flash-based resume that I stayed up all night to code.  I was lucky to change careers at the exact moment when many of my friends and co-workers were losing their jobs.

My first official year as a software developer was a great one. I learned how to write my first query, how to design a website and how to code in ColdFusion. I’ve been working with ColdFusion ever since, evolving as a developer as the language evolves. I also enjoy coding in ActionScript, JavaScript (go jQuery!), SQL, Java, PHP on occasion and anything else that comes my way, but ColdFusion remains my favorite language and in my biased opinion one of the best out there.


Seeking Fusebox Documentation

Posted: June 8th, 2011 | Author: | Filed under: ColdFusion | 3 Comments »

Does anyone know of a mirror to the Fusebox Documentation? The documentation link on Fusebox site http://trac.fusebox.org/ is dead.


Merry Christmas

Posted: December 22nd, 2010 | Author: | Filed under: ColdFusion, I'm Just Sayin' | No Comments »

May you all have a safe and happy Christmas filled with fun, friends, family and properly scoped variables.

<cfset variables.message = "Merry Christmas" />
<cfoutput>
#variables.message#
</cfoutput>

Truncate That List

Posted: December 8th, 2010 | Author: | Filed under: ColdFusion | No Comments »

Today’s ColdFusion code sample meets the needs of anyone that has to

  1. truncate a list if it’s over X characters
  2. add a suffix to the list in cases where it was truncated

Pardon the lack of proper indentation in the code sample below. If you copy and paste it into your favorite IDE the indentations will be restored.

Here’s the function call…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<cfscript>
	variables.aLongList = 
		"something, something else, a block of cheese, 
		the letter q, five golden rings, a shoe, 
		something additional goes here";
 
	variables.truncatedList = truncateList
		(
		theList = variables.aLongList,
		theDelimter = ",",
		truncatedListMaxength = 100,
		theSuffix = "...and many more"
		);
</cfscript>

…here’s the function…

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<cffunction 
	name="truncateList" 
	returntype="string" 
	hint="returns an author list that is under X characters">
 
	<cfargument name="theList" type="string" required="true" />
	<cfargument name="theDelimiter" type="string" required="true" default="," />
	<cfargument name="truncatedListMaxength" type="string" required="true" />
	<cfargument name="theSuffix" type="string" required="true" default=", et al." />
 
 
	<cfscript>
 
		// declare variables
		var local = structNew();
 
		local.theDelimiter = arguments.theDelimiter;
		local.theList = arguments.theList;
		local.theSuffix = arguments.theSuffix;
		local.truncatedListMaxength = arguments.truncatedListMaxength;
 
		local.currentListItem = "";
		local.currentItemLength = 0;
		local.delimiterLength = len(local.theDelimiter);
		local.i = 0;
		local.suffixLength = len(local.theSuffix);
		local.theListLength = len(local.theList);
		local.truncatedList = "";
		local.truncatedListLength = 0;
 
		// if the list needs to be truncated, loop through it
		if(local.theListLength > local.truncatedListMaxength){
			for(local.i=1; local.i <= local.theListLength; local.i = local.i+1){
 
				/*
				if the length of the current truncated list 
				+ the length of the current author string 
				+ the length of the delimiter 
				is GTE maxlength...
				*/
				local.currentListItem = listGetAt(local.theList, local.i, local.theDelimiter);
				local.truncatedListLength = len(local.truncatedList);
				local.currentItemLength = len(local.currentListItem);
 
				if(
					local.currentItemLength
					+ local.truncatedListLength
					+ local.delimiterLength
					>= local.truncatedListMaxength
				){
					/*
					...if the length of the truncated list 
					+ the length of the suffix 
					are greater than the max
					*/
					if
						(
						local.truncatedListLength 
						+ local.suffixLength
						> local.truncatedListMaxength
						){
 
						// remove the last item from the list
						local.truncatedList = 
							listDeleteAt
								(
								local.truncatedList, 
								listLen(local.truncatedList, local.theDelimiter), 
								local.theDelimiter); 
 
 
					}
					// add the suffix and break out of the loop
					local.truncatedList = local.truncatedList 
						& local.theSuffix;
					break;
 
 
				// else...
				}else{
 
					// ...add the current item to the string
					local.truncatedList = local.truncatedList 
						& local.currentListItem & local.theDelimiter;
 
				//	end if
				}
 
			//	end loop
			}
		}else{
			local.truncatedList = local.theList;
		}
 
		return local.truncatedList;
	</cfscript>
 
</cffunction>

…and just so you don’t have to type anything…

123
124
125
<cfoutput>
	#variables.truncatedList#
</cfoutput>