An often mentioned complaint by ColdFusion developers is the lack of operators commonly found in other programming languages such as JavaScript. For example, instead of the greater-than (>) symbol we have been restricted to the more wordy GT or GREATER THAN operator. However, in ColdFusion 8 this has changed and we have more freedom to use familiar JavaScript operators in <cfscript> blocks.

In the following series of posts, I will introduce the changes and show some simple examples. The first in the series is Arithmetic Operators.

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/). These haven’t changed from ColdFusion version 7 to 8.

A key change comes with the use of Unary Operators. The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean.

These operators work as they do in most other programming languages.

% (Modulus)

The modulus operator is used as follows:

var1 % var2

The modulus operator returns the first operand modulo the second operand, that is, var1 modulo var2, in the preceding statement, where var1 and var2 are variables. The modulo function is the integer remainder of dividing var1 by var2. For example, 12 % 5 returns 2.

In ColdFusion this is written:

<cfif myQuery.currentRow % 2></cfif>

A good use of the modulus operator would be to alternate row colours in tabular data. The above code could be wrapped around a CSS class, dynamically changing the name of the class on each row iteration.

++ (Increment)

The increment operator is used as follows:

var++ or ++var

This operator increments (adds one to) its operand and returns a value. If used postfix, with operator after operand (for example, x++), then it returns the value before incrementing. If used prefix with operator before operand (for example, ++x), then it returns the value after incrementing.

For example, if x is 10, then the statement y = x++ sets y to 10 and increments x to 11. If x is 10, then the statement y = ++x increments x to 11 and sets y to 11.

In ColdFusion, a simple example:

<cfset x = 10 />
<cfset y = x++ />
 
<cfdump var="#variables#" label="Increment Operator Test 1" />

The above code returns:

Increment Operator Test 1

Switching the order of the operator to be before the variable:

<cfset x = 10 />
<cfset y = ++x />
 
<cfdump var="#variables#" label="Increment Operator Test 2" />

The above code returns; note that both variables return 11:

Increment Operator Test 2

-- (Decrement)

The decrement operator is used as follows:

var-- or --var

This operator decrements (subtracts one from) its operand and returns a value. If used postfix (for example, x–), then it returns the value before decrementing. If used prefix (for example, –x), then it returns the value after decrementing.

For example, if x is three, then the statement y = x– sets y to 3 and decrements x to 2. If x is 3, then the statement y = –x decrements x to 2 and sets y to 2.

In ColdFusion, a slightly more complex example:

<cfscript>
//decrement the variable y
for(y=5; y > 0; y--)
{
	writeOutput(y);
}
//returns 54321
</cfscript>

The above code loops from 5 to 1, decrementing the value of y by 1 on each iteration. The returned output is therefore 54321.

We could now combine the increment and decrement operators to do even more complex operations. E.g.:

<cfscript>
//create a new array
arrTemp = arrayNew(1);
//create a new variable for the array counter
x = 1;
//loop y, decrement the variable y
for(y=5; y > 0; y--)
{
	arrTemp[x++] = y;
}
</cfscript>
 
<cfdump var="#arrTemp#" label="Combined Increment Decrement Operator Test" />

The above code loops from 5 to 1, decrementing the value of y by 1 on each iteration. At the same time, the value of x increments by 1 on each iteration and is used to define the array index, i.e. arrTemp[1].

The returned output can be displayed as follows:

Combined Increment Decrement Operator Test

Such code serves to demonstrate how you can set up complex operations without the need to use the following, antiquated operations:

<cfset x = incrementValue(x) />
<cfset y = y+1 />
<cfset a = decrementValue(a) />
<cfset b = b-1 />

- (Unary Negation)

The unary negation operator precedes its operand and negates it. For example, y = -x negates the value of x and assigns that to y; that is, if x were 3, y would get the value -3 and x would retain the value 3. This is not new to ColdFusion 8, but it is worth a mention.

In ColdFusion, this can be shown by the following:

<cfset x = 3 />
<cfset y = -x />
 
<cfdump var="#variables#" label="Unary Operator Test" />

The above code returns:

Unary Operator Test

For a long time now Adobe’s Flex IDE has been the one of the only tools for developing ActionScript 3 applications. Now there is an alternative in the form of PowerFlasher’s FDT 3.0.

Developed for internal by PowerFlasher, the FDT (Flash Development Tool) wowed freelancers so much that the company decided to launch it as a commercial product. Like Flex Builder, FDT is built upon the Eclipse framework and therefore has many similarities with other Eclipse-based tools, not least JDT upon which it is based.

It is great to see competing tools out there on the market and it can only serve to strengthen the popularity of the technology.

PowerFlasher’s tool can be found at http://fdt.powerflasher.com. It is really worth a look.

After installing ColdFusion 8 and Apache successfully you may still see an “HTTP 500 Internal Server Error” when navigating to a ColdFusion page. All is not lost, you simply need to configure, or check the configuration of Apache.

Apache requires very little post installation modification, but it is always good practice to check the httpd.conf file to ensure that the ColdFusion “install” scripts did what they were supposed to do.

If you haven’t confirmed that Apache is running, open your browser and point it to http://localhost/ (unless you specified a real URL during installation). You should see the Apache test page. If you see an error, review the Apache installation steps to make sure you followed all the steps correctly, and/or check your log files for more detailed errors.

Now we know Apache is running, but how about ColdFusion? Point your browser to the ColdFusion Administrator found commonly at http://localhost/CFIDE/administrator/index.cfm and see what happens. One of three possible failures could occur:

  1. Your browser prompts you to save the .cfm file to your computer. There a couple of possible resolutions to this. Firstly restart the Apache service. If this does not resolve the issue you will need to check the httpd.conf file to ensure that the ColdFusion module is being loaded. The file can typically be found in the C:\Program Files\Apache Software Foundation\Apache2.2\conf\ directory.
    Make sure that the DirectoryIndex has a reference to the index.cfm file (i.e. the default file):Apache dir_module DeclarationEnsure that the LoadModule jrun_module "C:/ColdFusion8/runtime/lib/wsconfig/1/mod_jrun22.so" is also present:

    Apache JRun Settings

    If you need to edit this file, restart the Apache service after you have saved the changes.

  2. You get a message that the CFIDE folder cannot be found. This is more likely to be a problem with where you placed the ColdFusion application during install. The default location is in the Apache directory (C:\Program Files\Apache Software Foundation\Apache2.2\htdocs), so check in the http.conf file to ensure the DocumentRoot is pointing correctly. Alternatively, copy this folder to your localhost webroot (e.g. C:\WebRoot) ensuring that the DocumentRoot points to your webroot (see the yellow box in the second screen-shot).
  3. You get another message which probably means that you need to reinstall ColdFusion, and/or Apache!

And that is it, you can start using ColdFusion and developing applications.

A few months ago I posted an article on Installing Apache on Vista, and it proved to be extremely popular. It appears that I was not the only one who found it a non trivial matter.

Now it is the turn of ColdFusion 8. ColdFusion 8 as we well know is the latest and greatest incarnation of the ColdFusion platform from Adobe. It has a lot of great new features such as cfimage, cfzip, cfexchange, some contentious features such as cfthread and cfinterface, and some not-so-necessarily-cool new “Web 2.0″ features such as cffeed and cfajax. But since this article isn’t about any of these, I better stick to the topic.

Like my article on installing Apache, installing ColdFusion on Vista is again not a trivial matter and involves only what can colloquially described as a “shed load of steps”. I’m probably being a little harsh towards ColdFusion as many of the problems I encountered were more closely related to Apache than ColdFusion.

NB: This article will assume that you have pre-installed Apache (although you could use IIS if so compelled), turned off Vista’s User Account Control (UAC), disabled any firewalls you have installed and finally, but most importantly, you have downloaded ColdFusion from the Adobe website.

Let us begin.

  1. Find where you downloaded your copy of the ColdFusion Installer. Right-click on the executable file and specify to “Run as Administrator”. The installer should start and you should see the screenshot below. Select “English”, or which ever your language preference is, and Click “OK”.

    1. ColdFusion Installer

  2. The ColdFusion Installation progress screen may or may not be briefly displayed.

    2. ColdFusion Installation Progress

  3. The Introduction screen will be displayed. Click “Next”.

    3. Introduction Screen

  4. The License Agreement screen will then be displayed. Agree to the “I accept the terms of the License Agreement” and Click “Next”.

    4. License Agreement

  5. The Install Type screen is then displayed. You don’t need to enter a serial number unless you are installing this into a production environment. Check “Developer Edition” and Click “Next”.

    5. Install Type

  6. The Installer Configuration screen should be displayed. Since we already have Apache 2.x installed as our web server (if you want to use IIS, you will need to skip steps 11.1 and 11.2), check “Server configuration” and Click “Next”.

    6. Installer Configuration

  7. The Sub-component Installation screen should be displayed. This is one of the noticeable changes from version 7 to version 8 of ColdFusion. Hovering your mouse over each sub-component will describe in more detail what each sub-component does. If you plan to integrate .NET (especially with WebServices) or carry out Flex development then make sure that the “.NET Integration Services” and “LiveCycle Data Services” items are checked. For simplicities sake, check everything and Click “Next”.

    7. Sub-component Installation

  8. The Select Installation Directory screen should be displayed. The default directory for a Serverconfiguration will be “C:\ColdFusion8″ on a Windows machine. Click “Next” to continue.

    8. Select Installation Directory

  9. As you have chosen to install LiveCycle Data Services, you will need to agree to a further Licence Agreement screen. Click “Next”.

    9. Licence Agreement (LiveCycle Data Services)

  10. The Adobe Livecycle Data Services ES Installation screen is displayed. You will need to enter a serial number into this screen for production environments. Since I am going to assume a development environment, simply click “Next”.

    10. Adobe Livecycle Data Services ES Installation

  11. The Configure Web Servers / Websites screen should be displayed. This is the point where we want to connect ColdFusion with Apache. By default “Configure web server connector for ColdFusion” is checked. We need to add Apache so Click “Add”.

    11. Configure Web Servers / Websites

    1. The Add Web Server Configuration screen is displayed, choose Apache from the drop-down.
    2. Add the relevant Apache directory paths, e.g.:

      11-2. Add Web Server Configuration (Directory Paths)

      1. The Configuration Directory C:\Program Files\Apache Software Foundation\Apache2.2\conf
      2. The Server Binary Directory C:\Program Files\Apache Software Foundation\Apache2.2\bin\httpd.exe
  12. The Review Configured Web Server screen is then displayed. If all the settings are correct, click “Next”.

    12. Review Configured Web Server

  13. The Choose Adobe ColdFusion 8 Administrator Location screen should be displayed. Since we are using Apache for our web server then the default Directory should be pointing to C:\Program Files\Apache Software Foundation\Apache2.2\htdocs. You can alternatively point this to C:\WebRoot or wherever you have set up your web project files. Select “Next”.

    13. Choose Adobe ColdFusion 8 Administrator Location

  14. The Adminstrator Password screen is then displayed, prompting for a password. Enter one, remember it (!!) and click “Next”.

    14. Adminstrator Password

  15. The Enable RDS & Password screen is then displayed. If you want to use this, check the box and provide an additional password. Don’t use RDS in a production environment. Click “Next”.

    15. Enable RDS & Password

  16. The Pre-Installation Summary screen is then displayed, detailing your configuration. This is your last chance to go back and make changes. If everything is OK, click “Install”.

    16. Pre-Installation Summary

  17. The Installing Adobe ColdFusion 8 screen is then displayed, showing a host of marketing messages.

    17. Installing Adobe ColdFusion 8

  18. The Please Wait screen is displayed, and be prepared to wait!

    18. Please Wait

  19. The Installation Complete screen is finally displayed and indeed the installation is complete. Now for the configuration! Click “Done”.

    19. Installation Complete

  20. Configuration and Settings Migration Wizard. Open up a browser and enter the url http://localhost/CFIDE/administrator/index.cfm to begin the ColdFusion 8 Configuration and Settings Migration Wizard. Enter your password and Click “Login”.

    20. Configuration and Settings Migration Wizard

  21. ColdFusion will now begin Configuring Server, which could take any number of minutes to complete.

    21. Configuring Server

  22. Once the Configuration Complete is displayed, you can login to the ColdFusion Administrator and start working, or playing, with the new interface, settings and Server Monitor.

    22. Configuration Complete

So, that only 22 steps! That may be the longest installation process you may go through, but the power now at your finger tips to produce hugely interactive websites is a compelling reason why to choose this version of ColdFusion, or indeed ColdFusion over other products.

ColdFusion has never satisfactorily removed whitespace from generated content, however, removing this whitespace can dramatically improve your website’s performance. Take a 100KB page for example. If 20% of the page is made up of whitespace, that is 20% that is unneccessary and 20% bandwidth cost that can be saved.

Currently there are two main ways a ColdFusion developer can prevent whitespace; via the ColdFusion Administrator and by including certain tags in their code:

1. ColdFusion Administrator

Under the Server Settings > Settings menu item there is a checkbox called ‘Enable Whitespace Management’. This checkbox should always be checked. According to the description, checking this checkbox “reduces the file size of the pages that ColdFusion returns to the browser by removing many of the extra spaces, tabs, and carriage returns that ColdFusion might otherwise persist from the CFML source file.” I am yet to be convinced, but it is worthwhile enabling it.

2. ColdFusion Tags

<cfsetting enablecfoutputonly="true"></cfsetting>

The cfsetting tag controls aspects of page processing, such as the output of HTML code in pages (inside and outside the cfsetting tag body). If enablecfoutputonly is set to true, HTML output is blocked if it is not wrapped in a cfoutput tag. Therefore, this tag ‘can’ be used to minimise the amount of generated whitespace.

<cfsilent></cfsilent>

The cfsilent tag supresses output produced by CFML within a tag’s scope. Therefore, you simply need to wrap the tag around anything you don’t want to output to the browser. As it does not return anything from with in it, so you have to be a little be careful when debugging.

<cfprocessingdirective supresswhitespace="true"></cfprocessingdirective>

One of the cfprocessingdirective’s purposes is to remove excess whitespace from ColdFusion generated content in the tag body. However, it does not affect any whitespace in HTML code. You can nest the tags and toggle supresswhitespace on and off, not that I ever identify a good reason to do so.

But there is a little known third way, using a servlet filter called Trim Filter.

Servlet filters are tools available to web application developers. They are designed to be able to manipulate a request and response (or both) that is sent to a web application.

Trim Filter lets you decrease the size of file your server will send to all clients. The filter removes extra spaces and line breaks from outputted documents. This can be especially useful for WAP/WML developers working with mobile devices, where the size for transferred documents is limited.

Setting up the servlet filter in ColdFusion

Using the Trim Filter servlet filter found at the following URL:

http://www.servletsuite.com/servlets/trimflt.htm

  • Download the trimflt.jar
  • Save trimflt.jar in the WEB-INF/lib folder in the ColdFusion Server wwwroot.
  • Edit the web.xml file in the WEB-INF folder in the ColdFusion Server wwwroot with the following code:

Trim Filter

  • Restart the ColdFusion Service

And now, when a ColdFusion page is invoked, the whitespace is suppressed and wow does it do a good job.

Killing ColdFusion is something I love to do!! This time I managed to kill ColdFusion by amending the Class Paths listed in the Java and JVM settings of my local instance of ColdFusion MX 7. When you amend any Java and JVM settings you need to restart the ColdFusion service and hope.

I jokingly commented to a colleague that this was a brilliant way to kill ColdFusion and I wasn’t far wrong.

Doing a clean install is out of the question, partly because of the time factor but also because there are generally a large number of settings, datasources, logs, etc configured on the server.

Fortunately ColdFusion is clever and stores a backup of the jvm.config file in the C:\CFusionMX7\runtime\bin directory. Simply deleting the broken config file and renaming the jvm.config.bak to jvm.config, followed by a ColdFusion application service restart fixes the issue (until the next time).

The Law of Demeter (LoD) as it is commonly called, is really more precisely the “Law of Demeter for Methods”. It is a design-style rule for object-oriented programs, but can be applied to ‘pseudo object-orientated’ languages such as ColdFusion (with regard to the use of ColdFusion Components). In essence it is the “principle of least knowledge” regarding the object instances used within a method. The idea is to assume as little as possible about the structure and properties of instances and their sub-parts. Therefore, it is okay to request a service of an objects instance, but if I reach into that object to access another sub-object and request a service of that sub-object, I am making an assumption of the deeper structure of the original object. This results in tight coupling, which is a sign of a poorly structured application.

The Law of Demeter says that if I need to request a service of an objects sub-part, I should instead make the request of the object itself and let it propagate this request to all relevant sub-parts, therefore the object is responsible for knowing its internal make-up instead of the method that uses it.

Stated in plain English:

  • You can play with yourself
  • You can play with your own toys (but you can’t take them apart)
  • You can play with toys that were given to you; and
  • You can play with toys you’ve made yourself.

Stated more succinctly, the Law of Demeter for Functions says that:

  • Your method can call other methods in its class directly
  • Your method can call methods on its own fields directly (but not on the fields’ fields)
  • When your method takes parameters, your method can call methods on those parameters directly; and
  • When your method creates local objects, that method can call method on the local objects.

The basic idea is to avoid invoking methods of a member object that is returned by another method. When you do this, you make structural assumptions about the container object that may be likely to change. The container object may later need to be modified to contain a different number of the contained objects, or it may end up being changed to contain another object which contains the original component object. If the ‘returned’ object isn’t a sub-part of the object whose method was invoked, nor of some other object, then it typically is not a violation of LoD to invoke a method of the returned object (particularly if the object was created by the invoking method).Using the Law of Demeter (LoD) you instead ask the container to invoke a method on its elements and return the result. The details of how the container propagates the message to its elements are encapsulated by the containing object. This results in weak coupling and strong cohesion, the general goal of high readability and maintainability of an application. This is highly desirable when building a ‘modern’ ColdFusion application as it is all too easy getting trapped into the bad-old-days of “spaghetti code”.

A side-effect of this is that if you conform to LoD, while it may quite increase the maintainability and ‘adaptiveness’ of your application, you also end up having to write lots of little wrapper methods to propagate methods calls to its components, which can add development time overhead.

Whether you love it or you hate it, LinkedIn for Groups now has the UK Adobe User Groups for ColdFusion, Flex and Flash.

The ColdFusion, Flex and Flash User Groups represent a central information resource for all UK Adobe developers. With the increasing importance of Rich Internet Applications, Rapid Application Development, the popularity Adobe software and industry recognition of the ColdFusion, Flex, Flash and AIR products, these user groups assist developers in defining their role within the Adobe and wider community. These groups aim to provide information resources and a chance to meet fellow developers and network within the community.

To join the groups and start networking, simply click on the appropriate link below:

UK ColdFusion User Group:

http://www.linkedin.com/e/gis/27811/79F5911ECBBE

UK Flex User Group:

http://www.linkedin.com/e/gis/27255/6343D73C42C2

UK Flash User Group:

http://www.linkedin.com/e/gis/27401/0E94A97A7DD4

The Flex and Flash User Group websites are still being designed/developed, but you can email them at

info [at] ukfxug [dot] org

info [at] ukflug [dot] org

respectively with ideas on what you would like to see on each site.

I recently taught a Fast Track to ColdFusion 7 (FTCF7) course and what struck me was the liberal use of the isDefined() function throughout the course material. Now, I confess, I have used the function many times in the past, but now more commonly use the structKeyExists() function. So why does Macromedia and now Adobe, still highlight the isDefined() function when, in my opinion, structKeyExists() is more efficient?

First we need to define what each one does:

IsDefined() evaluates a string value to determine whether the variable named in it exists.

StructKeyExists() determines whether a specific key is present in a structure.

On the Adobe Livedocs website, the documentation highlights the fact that the two functions are interchangeable in several situations, e.g. whenever a structure (i.e. associative array) is used. Now, almost everything is a structure, so that doesn’t help.

IsDefined() checks not just if a variable exists, but if it is also syntactically correct. This clearly has runtime implications. That is why, when dealing with structures you should avoid isDefined() in favour of structKeyExists().

I hope the FTCF8 course moves forward and ditches the liberal use of isDefined() and introduces more examples of alternative functions such as structKeyExists(). All too often I see examples which appear to be the path of least resistence, but not best practice.

Shall I mention the incomplete/non-functioning code examples in the FTCF7 course … !?! That’s another story.

I’m a ColdFusion freelance developer and as can often happen, I end up using a spare machine sitting in the corner of a room. Being relegated to the “dunce’s corner” is bad enough, but commonly the ColdFusion password has also been forgotten. This happened to me just the other day. So, how do we go about resetting the password?

Back in the ColdFusion 5 days you could edit the registry value:

HKEY_LOCAL_MACHINE\software\allaire\coldfusion\currentversion\server

set UseAdminPassword to 0 and restart the ColdFusion service, not forgetting to set a new password afterwards, especially if you’re on a production server.

Now with ColdFusion MX and MX7, you can’t but the process is not too tricky either. In fact there are two methods available to you.

First method:

You need to locate the password.properties file in the C:\CFusionMX7\lib\ directory. Opening the file, you will be presented with something much like this:

#Tue Apr 24 10:41:59 BST 2007
rdspassword=09GTH9 8O&>36& \\Q>[K\=XP \n
password=5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8
encrypted=true

Change the password to an alpha-numeric string of your choice and encrypted to false, much like this:

#Tue Apr 24 10:41:59 BST 2007
rdspassword=09GTH9 8O&>36& \\Q>[K\=XP \n
password=L3tM31n
encrypted=false

save the file and restart the ColdFusion service, you will be able to get into the ColdFusion Administrator with your chosen password.

Second method:

Locate the neo-security.xml file in the C:\CFusionMX7\lib\ directory. Opening the file you will be presented with a WDDX packet containing ColdFusion server configuration settings. The lines you will need to edit are the following:

<var name=’admin.security.enabled’>
<boolean value=’true’/>
</var>

Change the boolean value to false, like this:

<var name=’admin.security.enabled’>
<boolean value=’false’/>
</var>

save and restart the ColdFusion service. You can now log into the ColdFusion Adminsitrator without a password.

NB It is always recommended that a password be used for production systems.

« Older entries § Newer entries »