Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

ColdFusion 9 caching example

Sometimes with the new/updated features you don't get a chance to implement them right away. Well today I was working on a pulling in feed when I figured I finally had a good use-case to check out the updated caching enhancements in ColdFusion 9.

For this site I was working on I needed to pull in an RSS feed but HTTP calls are slow as there are usually factors outside of your control. The ColdFusion caching functions allows some nice control over what is cached, how often the cached is refreshed, and even when to drop it completley via the following two parameters:

  1. time span ( when we need to re-cache the item )
  2. idle/drop time ( When to drop it from memory when it hasn't been accessed for X amount of time )

[More]

Comments Comments (1) | Print Print | Send Send | 1327 Views

Query scripting bug in Coldfusion 9

I had a weird error this morning.

Named Sql parameter 'state ORDER' used in the query not found in the queryparams

Below is the code I had and it look fine to me:

view plain print about
1<cfscript>
2queryService = new query();
3queryService.setDatasource("cfdocexamples");
4queryService.setName("GetParks");
5queryService.addParam(name="state",value="MD",cfsqltype="VARCHAR");
6queryService.setSQL(
7"SELECT PARKNAME, REGION, STATE
8FROM Parks WHERE STATE = :state
9ORDER BY ParkName, State "
);
10result = queryService.execute();
11writeDump( result.getResult() );
12
</cfscript>
After staring at my code for a while and realising that doing that wouldn't fix anything I butchered played around with the syntax and found that after the WHERE clause you need to keep your SQL on one line. Making the following change to setSQL() fixed the problem:
view plain print about
1queryService.setSQL(
2"SELECT PARKNAME, REGION, STATE
3FROM Parks WHERE STATE = :state ORDER BY ParkName, State ");

I can't seem to find a reference as to how your SQL should be formatted but it seems the new line plays around with the deliminators and the way the named params are found.

I'm posting this now but will hopefully later find time to look in on query.cfc in the com/adobe/coldfusion folder under customtags to find the actual reason

Comments Comments (1) | Print Print | Send Send | 1731 Views

Blocking recent comment spam

There are a ton of ways to stop spam on blogs. This is my dirty (and not pretty) solution that I am adding to stop the recent wave of crap that is getting through the front end checks.

The long term plan is to put a back-end on this but for now here is v.00001

view plain print about
1<!--- Seperate with a pipe "|" as this is a regex list --->
2<cfset commentBlacklist = "coachoutletmall|wowgold" />
3<!---
4All the fields that we are going to check.
5Don't really need to check the email field as its not displayed.
6--->

7<cfset checkFields =trim(form.name) & trim(form.email) & trim(form.website) & trim(form.comments) />
8<!--- reFind to check the fields as they are past the other rules i.e. captcha --->
9<cfif reFindNoCase("#commentBlacklist#", checkFields, 1) >
10<cfoutput>Sorry deadbeat, I don't allow comment spam. If you feel you were wrongly blacklisted
11<a href="http://www.andyjarrett.com/blog/page.cfm/Contact-Me">Contact Me</a>
12</cfoutput>
13<cfabort>
14</cfif>

n.b. If you are on BlogCFC then this is for addcomment.cfm

Comments Comments (8) | Print Print | Send Send | 2270 Views

unix epoch with coldfusion

I never seem to remember that GetTickCount() gets the unix epoch time which is the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970 (from wiki

Comments Comments (0) | Print Print | Send Send | 1530 Views

cffile in cfscript quick cheat sheet

First time for using CFFILE within cfscript so thought I should document this for myself and anyone else.

Open and close a file

view plain print about
1myFile = expandPath( "somefile.txt" );
2fileObj = fileRead( myFile );
3writeOutput(fileObj);
4// OR
5myFile = expandPath( "somefile.txt" );
6fileObj = fileOpen( myFile, "read" );
7fileClose( fileObj ); // Once a file is closed you cannot access the object

[More]

Comments Comments (1) | Print Print | Send Send | 2004 Views

cannot cast void to non-void

If you ever see this error it means you're trying to output a function which doesn't return a value.

For me I was playing around with fileDelete() and without looking at the docs I assumed this would pass back a boolean to tell you if it was successful or not.

Comments Comments (0) | Print Print | Send Send | 1486 Views

Soundings mod for adding more questions

I've been playing around with Ray Camdens Soundings app adding some mods to improve my workflow.

The one which was really slowing me down this morning was the way you needed to save a question (with a couple of answers) then had to go back in to add more. All I've simply done to help myself is add a button. If you use the app and interested I've posted the full details over on the forum for everyone to see and comment on in the correct place.

Comments Comments (2) | Print Print | Send Send | 1589 Views

cfWheels adobe chat

cfframeworks has arranged an online introduction to cfWheels next Tuesday, 6th April, 2010 @ 12:00(GMT).

The URL for the event is: http://adobechats.adobe.acrobat.com/cfwheels-intro/

Comments Comments (0) | Print Print | Send Send | 1560 Views

Hibernate Dialect must be explicitly set error

This morning I fired up my dev environment to carry on working on my first ORM(Hibernate)/ColdFusion 9 app and got "Hibernate Dialect must be explicitly set". After some general tinkering and my first caffeine intake I finally woke up and realised my DB server wasn't fired up. Just thought I'd share as I didn't find much on Google about this.

Comments Comments (1) | Print Print | Send Send | 2361 Views

Reference card for ColdFusion Builder

ColdFusion Builder Logo Dzone have got a PDF reference card available via there site. Create by Terry Ryan, the Adobe CF Evangelist it coveres:

  • installing
  • starting a new project
  • connecting to servers
  • views
  • extensions
  • .... it goes on

A handy PDF to have saved locally and free as well, go get it at http://refcardz.dzone.com/refcardz/getting-started-adobe

Comments Comments (0) | Print Print | Send Send | 2005 Views

ColdFusion Builder out of Labs

You can now buy ColdFusion Builder for £200.92 ($299) from Adobe. Also included with your purchase is a complimentary copy of Flash Builder 4 Standard making the low price a great purchase for any developer!

Adobe® ColdFusion® Builder™ software is a highly customizable, Eclipse™ based IDE that enables developers to build ColdFusion applications faster than ever before. It also allows them to save time by managing the entire ColdFusion development cycle from concept to production with one easy-to-use tool

Comments Comments (0) | Print Print | Send Send | 1575 Views

ColdFusion online meetup is also downloadable

Since 2007 Charlie Arehart has runThe ColdFusion Meetup(actually founded in 2004). If you haven't heard of it then think of it as an online User Group with over 2000 members and over 120 meetups so far. The problem I have is that I can rarely make the actual sessions due to time conflicts but whats good is that you have always been able to watch the recording later. One other feature though of the meetups, which is what got me blogging this post, is that you can also download the recordings in the FLV format so you can watch offline later. Or in my case download it so I can watch with VLC as my Mac hates flash with a passion!

Comments Comments (2) | Print Print | Send Send | 1084 Views

A comment on using CFParam inside a CFFunction

This is a response/comment to Steve Goods post named: Using CFParam Inside a CFFunction. Its turned into a blog post because, well I suppose I am looking for a wider feedback on my thoughts.

When it comes to using <cfparam> in a <cffunction> I would never of even contemplated it up to a few weeks ago, mainly because of the framework I was using gave me other ways of checking of variables existence.But I've moved over to Framework One (FW/1) which uses the tag in its controllers for some of the demos and I've now adopted this in to my recent code.

This then got me thinking that I cannot find a solid case reason as to write

view plain print about
1if ( NOT StructKeyExists(myVar, "somekey") )
2{
3myVar.someKey = "0";
4}
5else if ( NOT isNumeric( myVar.somekey ) )
6{
7throw();
8}

when cfparam does that all in one go with basic type checking aswell.

view plain print about
1<cfparam name="myVar.somekey" default="0" type="integer" />

You could wrap the if() logic in a function to be used but then aren't you just adding an extra layer to your code to do something CF already handles?

Comments Comments (4) | Print Print | Send Send | 2485 Views

The squirrel has left the building

Neil Middleton has turned off his ColdFusion/Flex/Flash feed aggregator, Feed-Squirrel which has been up and running for near 4 years.

You can read all the details in his post, I just wanted to help pass on the news for the community.

Don't forget to turn off your automated ping'ing if you were aggregated by the site

Comments Comments (0) | Print Print | Send Send | 1349 Views

Submit jQuery tabs back on to itself

jQuery UI is a powerful set of interaction plugins for building RIA apps that run and the look the same across multiple browsers. Below is an example of using the tabs to hold multiple forms which submit back to themselves. The code is pretty straight forward and consists of two pages, the first one can even be a HTML page but the second one in my demo is a ColdFusion page to show the passed variables.
view plain print about
1<html>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4<head>
5<title>Submit jQuery tabs back on to itself</title>
6<!-- Use Google CDN for jquery files -->
7<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
8<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
9<!-- You can use Googles CDN for the themes as well -->
10<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/swanky-purse/jquery-ui.css" type="text/css" />
11<script>
12$(document).ready(function(){
13// set the tabs
14$("#tabs").tabs();
15// Capture the form's submit event
16$('.inlineForm').live('submit', function() {
17$.ajax({ // create an AJAX call...
18data: $(this).serialize(), // get the form data
19type: $(this).attr('method'), // GET or POST
20url: $(this).attr('action'), // the file to call
21success: function(response) { // on success..
22$('.ui-tabs-panel:visible').html(response); // update the DIV
23}
24});
25return false; // cancel original event to prevent form submitting
26})
27}); // END (DOCUMENT).READY
28</script>
29</head>
30<body>
31<div id="tabs">
32<ul>
33<li><a href="#tabs-1">Form 1</a></li>
34<li><a href="#tabs-2">Form 2</a></li>
35</ul>
36<div id="tabs-1">
37<!-- This is your first form. You could call this content in from Ajax?
38Also note the class name which is the reference point for jQuery
39-->

40<form action="receive.cfm" method="get" class="inlineForm">
41<input type="text" name="val1" value="" />
42<input type="submit" name="submit" value="Submit Form 1" />
43</form>
44</div>
45<div id="tabs-2">
46<!-- This is your second form. You could call this content in from Ajax? -->
47<form action="receive.cfm" method="get" class="inlineForm">
48<input type="text" name="val2" value="" />
49<input type="submit" name="submit" value="Submit Form 1" />
50</form>
51</div>
52</div>
53</body>
54</html>

The second page should be called receive.cfm

view plain print about
1<!-- This would process your form information and pass back a result to the user -->
2<cfsetting showdebugoutput="false" />
3<script>$("#dialog").dialog( {bgiframe: true, height: 140, modal: true} );</script>
4<div id="dialog" title="Done!">
5<p>Form submitted in to same tab</p>
6</div>
7<p>
8<cfdump var="#url#" format="text" label="Url variables">
9</p>

Comments Comments (2) | Print Print | Send Send | 4395 Views

Pet Rescue SOS, a new site in the works

Pet Rescue SOS is a site I've had a hand in putting it together, put simply, is the place where you can register your pets, have them assigned a unique tag and identity number which can used to identify and locate your pet anywhere in the world. This service is available online 24hrs a day and you have access to your own registration section from where you can manage your account and pets.

Below for anyone interested is some of the tech specs:

Comments Comments (1) | Print Print | Send Send | 1198 Views

Case sensitive selects in MySQL

There has been a couple of reasons recently that I needed to do a look up on a MySQL table using a case-sensitive Select statement. Its actually as easy as using "LIKE BINARY" instead of "LIKE" e.g.

view plain print about
1SELECT username, password
2FROM tablename
3WHERE password LIKE BINARY 'SOmE PAssWOrD'
Obviously if you are on a CFML engine don't forget
<cfqueryparam cfsqltype="cf_sql_varchar" value="SOmE PAssWOrD" />

Comments Comments (1) | Print Print | Send Send | 1055 Views

Darth Vader, Indiana Jones, Batman and SOTR2010

The title seems like the beginning of a joke but its all to do with Scotch On The Rocks in 2010.

So to answer questions like: Where the hell is SOTR2010?, is it going to be a tour, will it be in Amsterdam, go over to blog and read all about it

Comments Comments (0) | Print Print | Send Send | 638 Views

Changing the jQuery location for BlogCFC

Another title for this post could be adding a property to BlogCFC. Basically I wanted to leverage Googles ajax API rather than use a local version of the jQuery library. There are a couple of reason for this such as distributed CDN delivery, better caching on the users machine etc, actually you might want to read this post to understand why you would want to do this at all.

Back to adding a property.

  1. We're going to edit the blog.ini.cfm (settings) file in org/camden/blog and add the following
    view plain print about
    1#jQueryLocation=http://{Your Blog URL}/includes/jquery.min.js
    2jqueryLocation=https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
    The first line is there for redundancy incase you need to test something locally or you are on a closed system with no web access. The second line is what we are insterested in for this post and points to Googles Ajax Library
  2. In Blog.cfc in org/camden/blog add the following to (around) line 101. It should be obvious where its going
    view plain print about
    1<cfset instance.jquerylocation = variables.utils.configParam(variables.cfgFile, arguments.name, "jquerylocation")>
  3. Finally in your Layout.cfm under tags/ change:
    view plain print about
    1<script type="text/javascript" src="#application.rooturl#/includes/jquery.min.js"></script>

    to the following

    view plain print about
    1<script type="text/javascript" src="#application.blog.getProperty("jquerylocation")#"></script>

At this point we are pretty much done in terms of getting done what we set out to do. The following bit of code adds the new setting to the admin pages so we can edit this in the future. What I explain next will add the jQuery location field to the settings.cfm in admin/

  1. Around line 91 the variable "keylist" is set. Add to the end "jqueryLocation"
  2. Find in the form where the "blogurl" is set and underneath add the following
    view plain print about
    1<tr>
    2<td align="right">jQuery Location:</td>
    3<td><input type="text" name="jqueryLocation" value="#form.jqueryLocation#" class="txtField" maxlength="255"></td>
    4</tr>
  3. The final part is the validation rule. All I am doing is checking the value given is a valid URL. You could expand on this but for my purposes this will do just fine. Look for <cfif structKeyExists(form, "save")> which is the start of the validation, go down a few lines and among the other rules add
    view plain print about
    1<cfif NOT reFind("https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?", form.jqueryLocation)>
    2<cfset arrayAppend(errors, "Your jQuery location must be a valid URL.")>
    3</cfif>
Thats it, you're done now. Going to your settings and updating them will remove the commented out line we added in point one earlier but with a method to easily edit the location this shouldn't be a problem now

Comments Comments (0) | Print Print | Send Send | 1493 Views

CFBuilder and HTML 5 support pt 2

For anyone interested in this I have had an email from Adobes CF BUuilder bug tracking system about my bug(ID: 81384 ). They have acknowledge my bug and its targeted for: CF Builder 2.0, Alpha 1. Obviously there is a caveat that any targeting information an estimate and can change during the course of bug triage.

Comments Comments (0) | Print Print | Send Send | 658 Views

More Entries

BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .