The Thinking Lemur

21 Aug, 2008

My Development Future with ColdFusion

Posted by: Donnie Bachan In: Business| ColdFusion| PHP| Ruby

I absolutely love Adobe ColdFusion. I have been using it since version 3 and fell head over heals the first day I saw how easy it was to create a search directory, or send an email, or just about anything the average web application developer could want back in those days. It has matured tremendously in the past few years and with the release of version 8.01 can no longer be ignored as a fully featured web application platform. In my day job we use CF as our plaform for a site that gets a lot of traffic and since it is an integral part of the business we spent the money for CF Enterprise, but it was A LOT! As a small business owner as well, I am faced with the problem of developing with CF because of the pricing issue. Sure, shared hosting is an alternative and the prices have been coming down slightly but who wants to use shared hosting? We are real developers! The current movement to grid hosting has not engulfed the CF community thus far with no hosts that I know of making this offering. Again, I believe it is the licensing issue that is preventing this.

Another issue is the lack of affordable talent (or lack of talent in general) for ColdFusion development. Now, I am not saying that people shouldn’t be paid adequately for their talent but on average CF developers are quite a bit more expensive than say a PHP or Ruby developer and from a business standpoint it makes sense to use the more affordable option. The pricing point for ColdFusion Standard is not that bad but in my experience it is much better to use Enterprise in a J2EE deployment to achieve maximum stability on high demand systems.

So where does this leave me? PHP is a solid option, huge developer pool, it’s free, it works. Ruby is excellent as well. Companies such as 37 Signals have shown that Ruby can drive high demand applications. Java, is always an option but probably costs as much as ColdFusion to implement and support. I am really torn on this issue but financially I may have to move away from ColdFusion and focus on one of the free tools that will enable me to generate income and end with a positive bottom line. Adobe, please help us!

Paypal has been a headache for me ever since I’ve started using the API. I certainly hope that I’m not stupid and this is really easy and I’m just too daft to get this working easily but I’ve had to struggle with lack of documentation especially using ColdFusion 8. My woes started with the fact that the SOAP API doesn’t seem to work with ColdFusion 8 in J2EE configuration. Paypal does not support ColdFusion 8 and the forum posts are not very helpful. I do however like the NVP (Name-Value Pair) system for making API calls, it is quite easy to understand and implement in ColdFusion (and well any language really), that is, when the documentation is correct and you don’t have to submit a support ticket and wait a couple of days before you get the answer! It is recommended that you use the API Signature method if you use the NVP scheme and you are a smaller client but you can also use the API Certificate method, and this is where the problems start. The documentation on this is very ambiguous and should be better organised by Paypal. You feel like like you are in a treasure hunt with bits of information in one place and the rest scattered among several documents.

The main problem I had was using the Certificate method to make an NVP API call. ColdFusion 8 now has the ability to use a client certificate as part of your request, this is immensely useful and makes it a snap to get things working, once you know the steps. I’ll endeavour to outline them here:

1. Generate your API Certificate, this document has the instructions listed correctly, follow all steps except step 3 if you are using the NVP method: https://www.paypal.com/IntegrationCenter/ic_api-certificate.html. I got my OpenSSL for windows from http://www.slproweb.com/products/Win32OpenSSL.html. I had to install the Visual C++ 2008 as well to get this to work correctly.

2. Ensure that you note the Private Key Password used when creating the pkcs12 certificate, you’ll need this in the next step.

3. In you ColdFusion CFHTTP tag add the clientCert and clientCertPassword attributes. The clientCert will be the full path to your pkcs12 file and clientCertPassword is the Private Key Password. So your tag would look like this:

<cfhttp url=”https://api.paypal.com/nvp” method=”post” resolveurl=”no” timeout=”45″ clientCert=”C:\mycerts\paypal\my_paypal_cert.p12″>

4. The body of your call should be the standard parameters required for making NVP calls including the USER and PWD fields. These are the API Username and API Password generated when you created your credentials.

It all seems so simple now! I wish Paypal would really get detailed instructions for doing these things.

25 Nov, 2007

ColdFusion 8 CFWindow caching problem

Posted by: Donnie Bachan In: ColdFusion| Javascript

This iteration of ColdFusion is absolutely wonderful. Now anyone can AJAX and look like a DHTML guru with just a few lines of code. A previous post outlined the problem of not being able to refresh the CFWindow content. CF8 uses the EXT js library as of version 1.1.1 (I think) which by default does not provide a way to refresh the content of an element without actually manipulating the body property of the BasicDialog object. In CF the problem is even more complicated because you cannot just destroy a window and recreate it. There is no means to directly do this, so you have to access the underlying Ext library and call the destroy() function on the dialog. However, if you try to create a new window with the same name you get a javascript error. This is because the object is cached in the ColdFusion.objectCache object. Now, this is a good thing but the problem is that you cannot destroy the window easily. I would think this is a common task and should have been added. To work around the problem, you have to remove the element from the cache…

// get a reference to the Ext object
var mywin = Coldfusion.Window.getWindowObject(’my-window-1′);

// destroy the window and remove the elements from the DOM
mywin.destroy(true);

// remove the element from the ColdFusion.objectCache
ColdFusion.objectCache['my-window-1'] = null;

This would allow you to recreate the window via script without any problems. I think this is a serious oversight and a function should be added to allow for this operation.

The ColdFusion.objectCache is a very handy tool and should have better documentation.

I was going crazy trying to figure out why my href in the cfgridcolumn tag was not working with the new CFGrid in html mode. Apparently the appendKey attribute of the CFGrid tag is set to TRUE by default and this forces the href attribute to be a valid url. If you change the appendKey to FALSE, javascript functions work in the cfgridcolumn tags just fine….

So:

<code>
<cfform>
<cfgrid format=”html” name=”gContentLibrary” pagesize=”#request.maxrows#”
bind=”url:…”
>
<cfgridcolumn name=”title” href=”javascript:makeRequest(’viewlibraryitem’,{gridid:’gContentLibrary’})” display=”true” header=”Object Title” width=”250″ />
</cfgrid>
</cfform>
</code>
will not work but
<code>
<cfform>
<cfgrid format=”html” name=”gContentLibrary” pagesize=”#request.maxrows#”
bind=”url:…”
appendKey = “no”
>
<cfgridcolumn name=”title” href=”javascript:makeRequest(’viewlibraryitem’,{gridid:’gContentLibrary’})” display=”true” header=”Object Title” width=”250″ />
</cfgrid>
</cfform>
</code>

will work.

I may be stupid but it took a long time for me to figure this out and I didn’t even find a reference to this on Google….either, people aren’t doing this or everyone is much smarter than I am! Anyway I hope it helps someone out there…

26 Sep, 2007

Refreshing a CFWindow

Posted by: Donnie Bachan In: ColdFusion| Javascript

Recently I came across the situation where I wanted to refresh a cfwindow with a source tag that was bound to a hidden form field. When the value of the form field changed I wanted the window information to be reloaded, however since the value was being changed via javascript the onChange event was not being fired on the hidden field and so the cfwindow was not refreshing. I then decided to take another approach. I would use the ColdFusion.Window.create function and create a new window each time it is needed. In order to not have multiple instances of the window I would destroy the old window before creating the new one.

<code>
function getPageId()
{
return pageid;
}

function createWindow(name)
{

try
{
twin = ColdFusion.Window.getWindowObject(name);
twin.destroy(true);
}
catch (e)
{
// do nothing because the window does not exist
}
ColdFusion.Window.create(win, ‘Edit Page Properties’,
‘test.cfm?id=’+getPageId(),
{height:750,width:960,modal:true,closable:false,
draggable:false,resizable:true,center:true,initshow:true})

}
</code>

If I pass the same window name each time the window never refreshes! Even though pageid is changing. This seems to be because the window object is cached somehow. When I set the destroy(true) parameter another error comes up since the element is removed completely from the DOM. To work around this, each window created MUST have a unique name. If the name is not unique errors will occur since it seems that CF caches the name used for a window. I am not sure where and am in no mood to look for it at this point. Here is the code that works.

<code>
var winname = ”;

function getPageId()
{
return pageid;
}

function createWindow(name)
{
win = name + “_os_” + Math.round(Math.random() * 10000000000);
try
{
twin = ColdFusion.Window.getWindowObject(winname);
twin.destroy(true);
}
catch (e)
{
// do nothing because the window does not exist
}
ColdFusion.Window.create(win, ‘Edit Page Properties’,
‘test.cfm?pageid=’+getPageId(),
{height:750,width:960,modal:true,closable:false,
draggable:false,resizable:true,center:true,initshow:true})
winname = win;
}
</code>