November 18, 2009
ColdFusion proxy for After the Deadline
I recently switched our CMS spellchecker on PortlandOnline from Google's spellchecker to After the Deadline. After the Deadline is a new breed of spellchecker—likely very different from the spellcheckers you're used to using. AtD offers contextual spell checking so it can detect words that are spelled correctly, but used incorrectly. It also has an advanced style and grammar checker and offers helpful explanations of all the detected issues.
After the Deadline recently became the default spellchecker in Wordpress, and it's also offered as a TinyMCE plugin. However, the TinyMCE plugin requires a server side script to proxy AJAX requests. The only proxy script currently included with the plugin is for PHP so I ported the PHP script to ColdFusion. It's a fairly simple script, but I thought I'd share it so that others don't have to reinvent the wheel. (I did send it to the AtD developers so maybe it will be included in a future release…)
July 17, 2009
ColdFusion Tip: Query columns in correct order
One quirk in Coldfusion that I've had to battle before is that columns in query objects are sorted in alphabetical order. Normally this isn't too much of an issue because you just output the columns in the desired order when you're displaying the output on a page. But there are times when you need to loop over a list of the columns and you'd like them to appear in the order defined in the SQL query or DB schema.
You can use queryObj.columnList to get a list of query's columns, but as I already mentioned this list is sorted alphabetically. To get a column list in the correct order, use this simple trick:
ArrayToList( queryObj.getColumnNames() )
This method appears to be an undocumented method of the underlying Java query object.
May 13, 2008
Web standards awareness among CF developers
I've been thinking about this the last couple of days and have come up with a few possible reasons why there doesn't seem to be much focus on web standards in the CF community:
- The majority of CF developers are blissfully ignorant of web standards, or
- Since web standards are backend agnostic, CF developers rely on the general web development community for web standards information, or
- Now that it's been 6+ years since web standards entered the spotlight, the majority of CF developers are already well acquainted with these concepts and techniques and have already mastered them. Therefore further discussion is not needed, or
- Most CF developers are primarily backend coders. They spend their time coding CFCs, business logic, and data models, etc. Someone else does the frontend code for their applications so they aren't directly concerned with web standards.
If you're a ColdFusion programmer, I'd love to hear your thoughts on the issue. Particularly, I'd like to know:
- If you fall within one of the groups listed above and if so, which one(s).
- On a scale of one to five, what is your level of knowledge and expertise with web standards?
- Do you rely on the CF community for the majority of your web standards information/knowledge/training, etc or does it come from the general web development community as a whole?
- As a CF programmer, would you be interested in more conference sessions and/or blog articles devoted to web standards?
Please leave me a comment and let me know!
April 3, 2008
ColdFusion tip: Dynamic column names in ValueList()
Today I discovered that the ValueList() function in ColdFusion only works with a static argument in the form "query.column". So you can't use this function if you need to dynamically determine the column name at runtime. Luckily there is a nice little hack to work around this problem.
The ValueList() function returns a list of values from a particular query column. You can achieve the same result with the following expression:
April 1, 2008
ColdFusion spellchecker plugin for TinyMCE 3.0
We use TinyMCE as a WYSIWYG editor for our CMS at work. Version 3.0 of TinyMCE was recently released in which most of the application has been rewritten. Because of this rewrite, any plugins written for version 2.x have to be updated to be compatible with version 3.
The main third-party plugin that we use is a spellchecker plugin for ColdFusion servers. Since the plugin hasn't been updated, I took it upon myself to port the PHP spellchecker plugin provided with TinyMCE 3.0 to ColdFusion.
My ColdFusion spellchecker plugin is a complete port of the PHP plugin and supports both the Google spellchecker and Pspell/Aspell engines.
February 21, 2008
ColdFusion IsDate() gotcha
I must be a slow learner because I've been bitten by the following gotcha in the ColdFusion IsDate() function more than once. So I'm writing this here mostly for my own sake, but it may be of value to others also.
I've used IsDate() many times in form validation logic to verify that a user entered a valid date into an HTML field. Usually, I need to verify that the input is something like 02/21/2008 or 2-21-08, and this function has saved me from writing a regular expression to validate the correct format.
But it turns out that IsDate() is pretty liberal in it's definition of a "date". According to the ColdFusion documentation, IsDate() returns true "if [the] string can be converted to a date/time value." This means that the following strings are all considered valid dates according to this function:
- 4:03 pm
- 21-02-08 4:03pm
It's the dd/mm/yyyy format that's caused me trouble before. If I'm expecting a date in mm/dd/yyyy format and IsDate() allows the user to enter 21/02/2008 then strange things start happening in my applications.
My solution is to replace IsDate() with IsValid("USdate", string_value) which will only return true if the string is a valid date in the mm/dd/yy format (with 1-2 digit days and months and 1-4 digit years).
August 27, 2007
ColdFusion is the next FrontPage
Web professionals around the world rejoiced when Microsoft recently announced that they were discontinuing their infamous FrontPage WYSIWYG web authoring program. FrontPage, which was designed to make web site creation as easy as word processing, was scorned by web professionals due to the non-standard, proprietary Microsoft spaghetti HTML code that it generated. Many people could identify a web site created with FrontPage at first glance and the program and the sites that it created quickly became synonymous with amateur, wannabe web designers.
Unfortunately, the old FrontPage is now being replaced with a new “FrontPage.” Only this time it’s called Adobe ColdFusion 8. With the recent release of version 8, ColdFusion is being trumpeted as the quickest and easiest way to web applications. Sound familiar? Just replace “web application” with “web site” and you’ve got almost identical product slogans. What FrontPage attempted to do for static web sites, ColdFusion is trying to do for dynamic web applications. But this slogan doesn’t necessarily make ColdFusion a bad thing. Let me explain a little bit…
I use ColdFusion every day at work as a web application developer for the City of Portland. And I love ColdFusion because I honestly do believe that it is the quickest and easiest way to build powerful web applications. So when version 8 was recently released I was thrilled to learn about the new Ajax features designed to make building Ajax enabled applications easier than ever before. Having already built a couple of Ajax enabled web apps “the hard way” I was curious to see how well ColdFusion was able to simplify the process.
“Wow!” I said to myself as I hit the view source button in my browser, “Let’s see how they did it…”
It was at this point that the music suddenly stopped, the lights began to dim, and the smile quickly faded from my face. I’m a big advocate of standards-based web development and I usually try to create pages that conform to the XHTML Strict doctype. The first thing that I noticed was that while the HTML code that I’d used was valid, there were several validation errors in the ColdFusion generated code.
It seems that when it comes to creating a web site, whether it’s a static web site or a dynamic web application, if you want it done right you’ve got to do it yourself. This includes hand coding your HTML and handling the nitty-gritty details of Ajax enhanced web sites. This brought me to the conclusion that ColdFusion is just the next FrontPage. No doubt the new Ajax features will get used and abused by the less knowledgeable developers looking for the quick and easy solution. But smart developers who care about web standards and take pride in creating clean, semantic, valid HTML will do things the way they’ve always done them in the past—by hand. So the next time your tempted to use on of the new ColdFusion features that magically does everything for you, take a look behind the scenes at what’s really going on and evaluate if it’s really the best way to accomplish your task. You may find yourself joining me and doing it the hard way. But at least it will get done the right way!
P.S. Adobe, if you’re listening, it’s not too late! I’d love to be surprised by the next ColdFusion update to discover that you’ve fixed these issues that you’re putting forth an effort set a good example and do things the right way. If so, I promise I’ll never mention ColdFusion and FrontPage in the same sentence again!
March 9, 2007
Cfoutput group tip
Yesterday I experienced a problem with my first attempt to use the group attribute of the cfoutput tag. I was trying to use multiple nested cfoutput tags with the group attribute to create a table whose rows were grouped together by one column of a query. Within those groups, I wanted to group the rows by a second column value.
The problem I was having was that ColdFusion wasn’t grouping my 2nd level rows like it should. I assumed that cfoutput sorted the query appropriately in order to perform the necessary groupings. What I failed to realize was that you have to manually sort the query with the SQL order by clause.
In other words, any column used in the a cfoutput group attribute must be in the SQL order by clause (in the order that the cfoutput tags are nested).
Here’s a code sample:
<cfquery name="q"> SELECT Year,Month,Col1,Col2,Col3 FROM table ORDER BY Year,Month </cfquery> <cfoutput query="q" group="Year"> <h3>#Year#</h3> <cfoutput group="Month"> <table border="1"> <tr> <td colspan="3">#Month#</td> </tr> <tr> <td>Col1</td> <td>Col2</td> <td>col3</td> </tr> <cfoutput> <tr> <td>#Col1#</td> <td>#Col2#</td> <td>#Col3#</td> </tr> </cfoutput> </table> </cfoutput> </cfoutput>
May 4, 2006
Clearing a cached query in ColdFusion
The ColdFusion cookbook has a couple of recipes for dealing with cached database queries. In theory it's relatively simple. You can instruct ColdFusion to cache a query for a specified amount of time using the cachedWithin attribute of the <cfquery> tag. You can clear a cached query by calling the same query again, but setting the cachedWithin attribute to a past time. But I recently discovered an interesting issue regarding clearing cached queries…
It turns out that not only must the SQL query and <cfquery> attributes be identical (with the exception of the cachedWithin attribute), but both queries must also have identical whitespace formatting. In other words, the following will not work:
Because the 'clearing' query is indented more than the original query the cached query will not be cleared. So this is one time when whitespace really does matter.
<cfquery name="myQry" datasource="myDS"
order by last_name
<cfquery name="myQry" datasource="myDS"
order by last_name
Posted at 2:21 PM
February 8, 2006
Enabling web services over SSL in ColdFusion
I recently ran into a problem while trying to access a web service from within ColdFusion on our new testing server. It took me a while to get it working because the ColdFusion error messages weren’t very descriptive or helpful in pointing me to the cause of the problem. While searching for a solution, I came across a lot of unanswered forum posts from others who appeared to be experiencing the same problem so I thought I’d share my problem and the solution I finally found.
The ProblemThe <cfinvoke> tag that I was using to call the web service was returning this error message:
“Could not generate stub objects for web service invocation.”I tried to use the administrative console to add the web service, and it returned this error message:
“Error creating web service. Please ensure that you have entered a correct Web Service name or URL.”As I mentioned earlier, neither error message provided me with much insight as I know that there was nothing wrong with the web service itself (or the URL) because it was working fine from our development server. I discovered that I could not manually access the WSDL URL from within a browser due to a firewall restriction. After getting the firewall issue resolved I was still was getting the same error messages. So I began doing Google searches on the error messages. I discovered that these error messages seemed somewhat common, but I couldn’t find any solutions that seemed to apply in my case.
Finally I found a link that hinted that ColdFusion could not access any secure URLs (beginning with HTTPS) unless it contained the server’s SSL certificate (or the certificate’s issuer’s certificate) in its certificate store. Bingo! My web service was indeed located at a secure URL and the server’s SSL certificate was issued by an unknown certificate authority. After inserting the certificate authority’s certificate into the key store and restarting ColdFusion, everything magically worked. So how do you import a certificate into the key store? Well, instead of going through the effort to explain that here, I’m just going to point you to a few of the links that helped me figure it out: ColdFusion MX: Configuring Secure SSL Connection with LDAP Directory Server Enabling SSL SSL and the trusted keystore in Java
There is a custom administrator extension named CertMan that allows you to view, add, and delete SSL certificates from within the ColdFusion administrator. This GUI is way more user friendly than using the command line.