What is ColdFusion

ColdFusion is a dynamic web application server and a Rapid Application Development (RAD) toolkit that runs on Java. This document gets you started on ColdFusion (2016 release). This document talks about various aspects of ColdFusion from installing to deploying an application on a server.

Installing ColdFusion

Download the 32-bit server or the 64-bit server, according to your system configuration. You can download a trial version from the download site.

While installing, you can see two installation options:

Installing server configuration: The ColdFusion server configuration contains an embedded copy of Tomcat. To install the server configuration, follow the procedure in Installing the server configuration.

Installing JEE configuration: Deploy ColdFusion as a Java application on a standards-based Java Enterprise Edition application server. To install the JEE configuration, follow the procedure in Installing the JEE configuration.

If you are migrating from an older version of ColdFusion to ColdFusion (2016 release), refer to the migration guide.

Starting the ColdFusion Administrator

After installing ColdFusion, log in to the ColdFusion administrator to verify a successful installation.

The ColdFusion Administrator is a centralized interface for configuring your ColdFusion server. You can configure settings for mail, database connections, debugging options, security, and so on.

The default location of the ColdFusion Administrator login page is http://servername:8500/CFIDE/administrator/index.cfm, where servernameis the fully qualified domain name of your host machine. Common values for servernameare localhost or 127.0.0.1 (each refers to the web server on the local computer).

The default port number for the server configuration is 8500. If the port is occupied, then the next available port number is taken.

ColdFusion Builder

ColdFusion Builder is an IDE for CFML-based projects or applications using ColdFusion Enterprise or Standard server. Since ColdFusion Builder is based on Eclipse, it works easily with other Eclipse plugins.

Like any IDE, ColdFusion Builder is equipped with a code editor, a compiler, a debugger, and code assist.

Strings

In ColdFusion, a string is a quote ( ' or " ) followed by zero or more letters, numbers, or symbols, and followed by another quote ( ' or " ). For example,

myString="Hello";

myString1="Welcome to ColdFusion.";

myString2="a123";

There are string functions in CFML for string manipulation and display. To see a list of all string functions, refer to String functions.

For example, use the len function as follows:

<cfscript>
myString="That's one small step for man, one giant leap for mankind.";
myStringLen=Len(myString);
WriteOutput(myStringLen);
</cfscript>

The output is 58, which is the length of the input string including spaces.

Arrays

In ColdFusion, you can create arrays explicitly, by using a function to declare the array and then assigning it data, or implicitly by using an assignment statement. You can create simple or complex, multidimensional arrays.

You can declare arrays of strings, numbers, or objects. For example,

myArray=[1,2,3,4,5];

myArray1=["ab","bc","cd","de"];

To create an array, first create an array object using the ArrayNew function. For example,

<cfscript>

myArray = [];

myArray=[0,1,1,2,3,5,8,13,21];

</cfscript>

The example creates an array object for a one-dimensional array and then populates the array with the Fibonacci series.

Array loops

Struct loops

You can iterate over each struct member and apply struct operations. For example,

myStruct={a=1,b=2,c=3,d=4,e=5};

for (key in myStruct){

WriteOutput(#key# & ":" & #myStruct[key]#); // Outputs a:1 b:2…

}

List loops

You can iterate over each element in a list. For example,

myList="a,b,c,d,e";

for (element in myList){

WriteOutput(element); // Outputs abcde

}

Data handling in ColdFusion

Handling record sets in databases is a key component of ColdFusion. ColdFusion has built in support for many databases including MS SQL, MySQL, Oracle, Derby, and Postgres.

You can use <cfquery> and call a SQL statement using a datasource. A datasource is the collection of settings you can use to communicate with a database, such as, database type, sever, port, tablespace, or database, username and password.

Application.cfc

Application cfc is used to define settings that are common to an application. Application.cfc defines application level variables and event handlers (functions invoked at various application lifecycle events).

There are various lifecycle events in your ColdFusion applications. To know more about the events, refer to the Application.cfc reference.

For example,

component {

this.name = "AppName";

this.datasource = "AppDataSource";

this.sessionManagement = true;

}

ColdFusion ORM

ColdFusion Object Relational Mapping (ORM) lets you access and manipulate databases using CFCs. ORM is built on Hibernate. Using ORM, you can build object oriented applications. You can concentrate on building the business layer without worrying about CRUD operations to the database. ORM generates SQL statements and defines the CRUD methods for you.

Update the Application.cfc as follows:

component{

this.name="artgallery";

this.ormEnabled=true;

this.datasource="cfartgallery";

}

There is a list of ORM-related configuration for your CFC. Find it here.

Next, map an object to a database and define the persistence, as shown below:

component persistent="true"{

property name="artistid" generator="increment";

property firstname;

property lastname;

}

Create a ColdFusion page to list all artists with first and last names, as shown below:

Object-oriented concepts in ColdFusion

Object-oriented programming in ColdFusion relies heavily on ColdFusion Components (CFCs). A component encapsulates data and the methods that can manipulate that data. Its parallel in java is the Java “Class”.

A CFC consists of:

Data/variables containing data.

Methods to manipulate that data.

Using a CFC, you can:

Share properties and variables between methods

Share properties between methods defined in other CFCs

Inherit methods and properties

Create a CFC (greetingsobjectFile.cfc) that displays the string "Hello World!":