the singularity of being and nothingness
Posts tagged ColdFusion
Multi-CFML Engine Environment on Apache
May 17th
For local development, I typically deal with ColdFusion 10 and Railo 4. Recently, however, the pain of switching back and forth (copying files and what not) has surpassed the threshold of feasibility. Plus, I would *really* like to be able to easily test ColdFusion 9 and ColdFusion 11 as well (specifically for compatibility with ContentBox).
The ideal setup is that I would install ColdFusion 9, ColdFusion 10, ColdFusion 11, and Railo and simply create local sites which all run off of the same core code, something like:
- mysite.cf9.com
- mysite.cf10.com
- mysite.cf11.com
- mysite.railo.com
I think it is fate or Providence, but the genesis of my search for a solution to this problem coincided ALMOST PRECISELY with cf.Objective 2014. While I wasn’t able to attend, the amazing Gavin Pickin presented on a topic entitled Setting up your multi-engine environment:Apache, Railo and Coldfusion – Play Nice Kids. Yes, I know: exactly what I was needing to do.
I followed along as best I could with the PowerPoint, and after only a few missteps, it was working.
Gavin, you are the man. The next time I see you I will buy you several beers 🙂
If this is something that you’ve been interested in doing for your own development environment, be More >
ColdFusion ORM – Collection…was not processed by flush()
Nov 14th
This is more for my own memory, but perhaps it will be useful to others 🙂
Let’s say I have the following entities:
User.cfc
component persistent="true" entityname="User" table="User" { property name="UserID" fieldtype="id"; property name="Name"; property name="Age"; property name="Group" fieldtype="many-to-one" cfc="Group" fkcolumn="GroupID"; }
 Group.cfc
component persistent="true" entityname="Group" table="Group" { property name="GroupID" fieldtype="id"; property name="Name"; property name="Activities" fieldtype="one-to-many" fkcolumn="GroupID" linktable="Activity" inversejoincolumn="ActivityID"; }
Ok, so let’s also imagine that I’m trying to leverage the postDelete() event to make an audit record of any User deletions that I make:
// function postDelete( entity ) { // get properties from entity that I want to log ... ... }
When I try to do this, I get something like:
collection >> [Group.Activities] was not processed by flush()
I banged my head on this wall for a while, until I finally figured out the issue.
The issue is the “laziness” of the “Group” property on the User entity. Since I have no value specified, it is equivalent to having specified “lazy=true”. Since (I assume) the Group property is not being fully “loaded” during the delete operation, there’s no chance that it’s own “Activities” property is loaded either…hence the error.
Anyway, to fix this, I merely added “lazy=false” to my “Group” property. Once in place, I was able to More >
Resolutions and Stuff
Jan 2nd
I’m not big on resolutions. When I’ve made them in the past, I typically last about 3 whole days before they’re broken and forgotten. Besides, there’s something a bit odd about resolutions anyway. After all, why would we wait until a New Year to do something (lose weight, exercise more, etc.), when it makes a lot more sense to do these things *before* the year begins so that we have the benefit of whatever change for the whole year?
Ah, but that’s the neurosis of the Western mind; what can be done about it? Nothing 🙂
But even though I’m reticent about making resolutions, I have been thinking about the year that lies ahead, particularly from a professional standpoint. Over the last year, I’ve been very productive in my professional development. Particularly in relation to ColdFusion, JavaScript and SQL, I have tremendously expanded my competency, and I feel quite comfortable with where I am as a developer.
However, as we all know, complacency can be a silent killer. While it may not immediately harm a person in relation to their employment prospects, it can be detrimental in the long-term, if nothing else than by souring them to the prospects of learning new skills, More >
ColdFusion Gotcha: Switch Statement in CFScript
Aug 30th
The other day, I was reworking a bit of tag-based code to use my preference of <cfscript> syntax. While doing this, I ran across something like this:
<cfswitch expression="#img.extension#"> <cfcase value=".gif,.jpg"> Not transparent </cfcase> <cfcase value=".png"> Transparent </cfcase> </cfswitch>
No rocket-science here, just a simple switch statement which just so happens to have a “case” which evaluates a list of values. Honestly, I’m not sure I had ever done a list of values in a <case>, but it just works.
Thinking nothing of it, I quickly converted it to <cfscript> syntax:
<cfscript> switch(img.extension) { case ".gif,.jpg": writeoutput("Not transparent"); break; case ".png": writeoutput("Transparent"); break; } </cfscript>
At first, I thought it was working. But as I tested a bit more, I noticed that it wasn’t. No error, per se, but the “case” was not evaluating as it did in the tag-based equivalent.
Turns out you have to do something a bit different with <cfscript>. Here’s an alternative that will replicate the tag-based functionality:
<cfscript> switch(img.extension) { case ".gif": case ".jpg": writeoutput("Not transparent"); break; case ".png": writeoutput("Transparent"); break; } </cfscript>
According to the docs,
Multiple case constant: statements can precede the statement or statements to execute if any of the cases are true. This lets you specify several matches for one code block.
Ah, so More >
How I Got Started in ColdFusion
Aug 1st
This is my contribution to the thread started over at Ray Camden’s site. If you’re a CF developer, be sure to share your thoughts too!
Like all good stories, this one begins with bourbon and cheap cigars.
Years ago, I was in a poker society with my best friends in the world. We were liturgically serious about our poker, going so far as to create the framework for member rules, organizational bylaws, and the like.
At some point, it became apparent that our group needed a website–just some place online where we could store information for our organization. Though I had no idea how to do it, I volunteered to create the website. A ridiculous number of hours–and a hacked together Photoshop-to-HTML export–later, our website was born.
It was hacky, impossible to maintain, and *not* secure (despite my lame attempt to create a login). Yet through the process, I discovered that I LOVED making websites.
Fast-forward a year and a half, and I landed my first job as a web designer. I was laughably under-qualified, but I got my shot and I threw all my energy into it. I had a lot of success, and felt good about my decision. Even after moving from a “hobby” to More >
Renaming Files in CFScript
May 13th
I’ve recently taken to writing all of my components in pure cfscript. To me, they look cleaner and are easier to navigate. Plus, I just really like cfscript 🙂
One of the challenges, of course, is that after using tags for so long, it can be sometimes challenging to find equivalent functionality in cfscript. Some tags expose functionality that may not be readily apparent in cfscript functions provided.
Take cffile’s “rename” action. If you look through the list of “FileXXXX()” methods, you’ll see a lot that correspond 1-to-1 with the tag actions. However, interestingly enough, there’s no FileRename() function.
Now you might think that this means that files can’t be renamed with using cffile. Wrong! You can simply use FileMove() to accomplish the rename. And actually, if you think about it, this makes sense. After all, when you move a file, you literally move it–so if the file is moved to a different or same location with a new file name, that’s the file that’s getting moved…no copy to worry about cleaning up after the face.
Ok, enough of that. So here’s a pretty ordinary file rename with cffile:
<cffile action=”rename” source=”c:\files\memo\readonlymemo.doc” destination=”c:\files\memo\normalmemo.doc”>
But we can accomplish precisely the same thing with FileMove():
filemove(c:\files\memo\readonlymemo.doc, c:\files\memo\normalmemo.doc);
Pretty nice!
Share this:
Gotcha with Dynamic Component Method Invocation
Sep 30th
In an app I’m currently working on, I came across the need to be able to invoke methods from a particular component dynamically. On the surface, this is pretty simple:
myComp = createobject("component","com.utils").init(); dyn = myComp[methodvariable]; dyn();
While this technically *works*, there is one huge gotcha: there does not appear to be any persistence of the initialized component from init() to dyn(). That is, if the init method, say, sets up datasource names and other component properties, these will no longer be available in the invocation of dyn(). Not a big deal, I guess, if you don’t have need of the init function…but a killer if you do.
Fortunately, it’s easy enough to work around this. After you’ve instantiated the component, just use to call the dynamic method:
<cfinvoke component="#myComp#" method="#methodvariable#" /> (cfinvoke is still tag-bound...sorry! :))
Anyway, easy enough, but something a person can easily spend FAR too much time trying to work out. Uggh.
Share this:ColdFusion and ORM…Yummy!
Mar 2nd
The other day, I was flipping through the ColdFusion docs (yeah, super exciting!) and came across the section about ColdFusion's support of ORM. If you're not familiar with it (I wasn't really until a few days ago), ORM stands for "object-relational mapping." While it sounds a bit overly technical, ORM is basically a way to interface objects in code to relational databases that levels the playing field, allowing your code to be more or less agnostic about what kind (or kinds) of databases that it's connecting to.
At first, I was unimpressed, but then I took a few moments to think about it. How often have I had to switch between database systems? Plenty. And how fun was it to have to go back and rework my code to account for the differences in typing and syntax? It wasn't. With ORM, however, alot of these headaches are removed because you can create an abstraction layer in your application using ORM to not really have to worry about what datasource you might be connecting to.
Now obviously, the subject of ORM is much more complex than my admittedly weak description. However, after a lot of reading I feel like I have a decent More >
Turning to the Darkside…of <cfscript>
Jan 22nd
During a lull at work the other day, I was reading about the extended capabilities that have been added to <cfscript> in ColdFusion 9, like being able to create queries and entire components…
Honestly, until recently I've not really used a whole lot of . I'm not really sure why…just not something that interested me a whole lot. You think it would: I like JavaScript syntax a lot, and translating these skills to <cfscript> is pretty straightforward. Still, not a whole lot of experience.
Honestly, I think a lot of it is that there's something comforting about the tag syntax. It's easy to see a balance in your code, and even easier–depending on your IDE–to see where you've completely borked something, left out a tag…whatever. Some of it, out of necessity, is that not every tag has a equivalent, although efforts are underway to remedy this…Whatever the reasons might be, it's super-simple to get used to the tags and then feel quite lost in <cfscript>.
The revelation for me was kind of interesting. For starters, outside of the very specific tags like, say, <cfexecute>, what are the majority of the tags that you use in a regular swatch of code? For me, it's a More >
Converting ColdFusion Queries for Ext
Jan 21st
At my new job, we use Ext fairly regularly to get some pretty cool AJAXiness up in the mix of things. To familiarize myself with Ext (I’ve not really used it until now), I recently downloaded the newest version and have been playing around with it quite a bit.
One of the elements I like quite a bit is the data grid. Like most other things, Ext makes it pretty simple to pull off a slick sortable, pageable data grid with very little work.
Of course, given that I use ColdFusion alot, I decided to hook up a grid to a remote CFC call. While the call itself is easy enough to do, there is one issue: the JSON that CF returns is in a format that Ext cannot quite understand.
Now there are a bunch of pre-built converters out there, some more robust than others (and a few I couldn’t quite get to work).
So in the spirit of trying to figure it out for myself, I wrote up a simple function in ColdFusion that will take a regular query and convert it into happy JSON that Ext can deal with.
First, here’s our function to create our generic query:
<cffunction name="getPosts" access="remote" returnformat="json" output="false" hint="Gets list/detail More >