Open a Terminal. Type “sudo open ” in the terminal. Then navigate to the “ColdFusion 8 Install.app” that you unzipped. Drag it over to the Terminal app, it will paste the path for you (should look something like “sudo open /Users/renaun/Desktop/downloads/ColdFusion\ 8\ Installer.app/”. Click enter.

Now we are in the ColdFusion Wizard, here are what I selected as the installation options

Clicked Ok

Clicked Next

Clicked “I accept….” and then Next

Checked the Developer Edition and then clicked Next

Select the “Server Configuration” option , then click Next

I had no other installs, so left it checked No, and clicked Next

I did not want the documentation, startup scripts, or Adobe LiveCycle Data Services ES. I unchecked all 3 and then clicked Next

I left the default install directory “/Applications/ColdFusion8″, and clicked Next

I did not need to update from earlier versions of ColdFusion, so I left it No and clicked Next

I left “Configure web server connected for ColdFusion” selected and clicked on the Add button. Use the values below to fill out the form, then click OK

Web Server: Apache

Config. Dir: /Applications/xampp/etc

Dir and file name of server binary: /Applications/xampp/xamppfiles/bin/httpd

Dir and file name of server control script: /Applications/xampp/xamppfiles/bin/apachectl

Click Next

I put my CFIDE in the default Mac web sites folder, which I changed the “DocumentRoot” value in the /Applications/xampp/etc/httpd.conf file of xampp also. So select your default web server DocumentRoot. Either: /Applications/xampp/xamppfiles/htdocs /Users/renaun/Sites/ Click Next

Enter a password for the CFIDE administration login and click Next

Enabled RDS and give a password if you want. I did not, click Next

Provide your Mac OS X user’s password and click Next

Click Install and wait for it to install

Click Ok, and it will open the CFIDE administration login wizard

Log in with your password setup eariler in the wizard

To Start/Stop ColdFusion manual open a Terminal app and type in Either: sudo /Applications/ColdFuions8/bin/coldfusion start- or - sudo /Applications/ColdFusion8/bin/coldfusion stop

Install the standalone Flex Builder 3, click Next to everything and install it in the default location.

Code Project Setup: Now it’s time to start Flex Builder 3 and get the project’s up and running.

Setting up the Cairngorm Source project

In Flex Builder, in the Navigator view, right click and select “Import…” context menu item.

Now select General->Existing Projects into Workspace and then click Next.

Click the top right “Browse…” button and navigate to the path you unzipped the Cairngorm source code to. For me this was /Users/renaun/Desktop/downloads/Cairngorm/. Click Ok

You should see a project called “Cairngorm” in the Projects list. Make sure its checked and click the Finish button

Setting up the CairngormAccountManagement project

In Flex Builder, in the Navigator view, right click and select “Import…” context menu item.

Now select General->Existing Projects into Workspace and then click Next.

Click the top right “Browse…” button and navigate to the web DocumentRoot where you unzipped the example source code. For me this was /Users/renaun/Sites/CairngormAccountManagement/. Click Ok

You should see a project called “CairngormAccountManagement” in the Projects list. Make sure its checked and click the Finish button

Click on the CairngormAccountManagement project in the Navigator pain, right click on select the Properties context menu item

Select the Flex Build Path page, and the Source Path tab. Click the “/Users/renaun/Sites/com/” folder and click the Edit button

Navigate to the “com” folder of your respective web’s DocumentRoot

Change and click Ok

The Walkthrough of How and the Whys The following part of the tutorial will walk you through the basics of Cairngorm and how to hook up ColdFusion as the backend of the CairngormLogin example. You can read more about the CairngormLogin example on Alex Uhlmann’s blog and Neil Webb’s posts.

First, we need to cover some of the basic Cairngorm terminology. One of the best ways to describe the Cairngorm framework is with the Cairngorm Diagram Explorer (http://cairngormdocs.org). Its split up into the Model View Controller (MVC) model with parts like ModelLocator, FrontController, ServiceLocator, BusinessDelegates, Commands, and Events.

In the process of explaining some of these Cairngorm concepts, we’ll take the original CairngormLogin example and add a working ColdFusion 8 backend (using MySQL from XAMPP), change LoginVO into AccountVO, add a type to the AccountVO, and create a AddAccount view to add more accounts.

A good place to start is in the CairngormLogin.mxml file. Go ahead and open up the file and take a look at the bottom half, the code after </mx:Script>. In this section of the code the Services, Controller, and main Views are defined. Lets dive into the Services class. Double Click on the “Services” text of the line of code “<services:Services id=”loginServices”/>, and then click F3. This will take us right into the /com/adobe/cairngorm/samples/login/Services.mxml file. The ServicesLocator class of Cairngorm provides a one stop shop for all services of the application. This is nice and handy place to make all your service declarations, be it RemoteObject, WebService, or HTTPService. The com.adobe.cairngorm.samples.login.LoginService.cfc component expose a “login” method. To make this service available lets add it to Services.mxml, here is the code:

Our loginService now is defined to look to the com.adobe.cairngorm.samples.login.LoginService.cfc for any method calls on it. Lets go to the ColdFusion for a second. Open up the LoginService.cfc and take a look at the “login” method. It takes an argument of AccountVO, which we’ll define both on the ColdFusion and ActionScript side, checks the username and password, and then returns an AccountVO if a valid account. You can find the ColdFusion AccountVO at com.adobe.cairngorm.samples.login.vo.AccountVO.cfc. It is a basic CFC with some properties and init script.

Lets take a step back and go back to the CairngormLogin.mxml page. With a valid Services defined in Services.mxml we are ready to talk about how the actual user interaction goes from the screen to our Services CFC and back into our application. The next important step in the Cairngorm arichecture is the Controller. In our case, the com.adobe.cairngorm.samples.login.LoginControl class. Double click on “LoginControl” in the line of code “ and press F3. A FrontController is the brains of the operation. It knows what requests made by the user interaction on the View side of things correlate to the Commands/Business Delegates on the application business logic side. This is done with a basic lookup mechanism which the FrontController defines the key as the Event type and the value as the Command class. Under the hood of the FrontController implementation is the magic where it sets up event listeners on the specific events to be ready to fire of any Commands.

This also makes it easy to define business logic regardless of the applications View or view state. Any place in the application you dispatch a event with the type “LoginControl.EVENT_LOGIN” and it calls the LoginCommand. The Commands go and do their stuff and then come back with some result. All the while don’t have to think about creating the Command or worrying about handling its result in the same place as where you made the call (this is where the ModelLocator comes in which we’ll talk about more in a bit).

Ok, enough rambling, lets look at the code. We know that LoginControl defines a lookup for “LoginControl.EVENT_LOGIN” to a Command called LoginCommand. The EVENT_LOGIN event is fired on the Login button in LoginPanel.mxml.

You see that upon clicking on the Login button it fires off a local method called “loginUser()”. In the method it creates an AccountVO, passes that into a new LoginEvent, and then dispatches the event. No LoginCommand in site. Pay attention to the “!login.isPending”, the login property is set back on the CairngormLogin.mxml page:

...<view:LoginPanelid="login"login="{ model.login }"/> ...

Now we have are torn between talking about the “model.login” (ModelLocator) and continuing following the process of the Login event. The model will have to wait again. We know that the FrontController will create and fire off (calls the execute method) on the LoginCommand behind the scenes because we dispatch a LoginEvent (which defaults to LoginEvent.EVENT_LOGIN type). Lets take a look at the important parts of the LoginCommand class:

The execute method contains a new class, the LoginDelegate. The BusinessDelegates create a pseudo proxy for the actual method calls on the Service classes. They also define a pattern to get the results (result/fault methods through a IResponder). You’ll see the “delegate.login(loginEvent.accountVO)” makes a call on the delegate that in turns makes the call on the “loginService” from our Services.mxml.

The call is made and the result or fault method is called by the responder. You’ll see a “event.result” property inside the result(event:Object) method. We defined the LoginService.cfc’s login method to return an AccountVO, therefore we can cast the event.result as an AccountVO and do our check on the accountid.

The use of RemoteObject service provides us with resquests/responses in the Action Message Format (AMF). The AMF format allows for type classes. We created the AccountVO.cfc, it was just a plain CFC. To correlate this with an ActionScript class that the AMF serialization can convert to we define the AS class like so:

The special code that lets AMF know how to convert the class is [RemoteClass(alias="com.adobe.cairngorm.samples.login.vo.AccountVO")]. If you where to use ServiceCapture or Charles HTTP you would see the type request and response as AccountVO objects.

What takes us back to the View state is the code in the LoginCommand that changes the model, “model.login.isPending = false;” and “model.workflowState = ModelLocator.VIEWING_LOGGED_IN_SCREEN;”. The first changes the enabled state of the LoginPanel.mxml’s Login button back to be enabled. The 2nd code snippet is where the magic of the View change happens. This also is one of the best illustrations of the ModelLocator pattern and its power when couple with ActionScript’s binding capability.

First lets talk about the model in general. The ModelLocator pattern provies a single place to storage data for the application. It implements a singleton pattern so only one copy of the data is present. It is basically a holding place for a bunch of global data. So the same pitfalls of global variables do apply here, but when used in connection with Commands you can structure model manipulation to maintainable business logic chunks.

Lets look at the model.workflowState property. Here it is getting changed on a LoginCommand. But what does it do, well back to the CairngormLogin.mxml file. The ViewStack (id=”appView”) references it in the binding of selectedChild to a function getView(model.workflowState). Inside getView() we see that the model.workflowState is check and defines which child the ViewStack displays. Interesting, so changing one value on the model in an LoginCommand class fired off in the LoginPanel view caused the ViewStack to change its view.

Now with some changes to AccountVO, I’ll leave it up to you to check out the other changes in MainPanel.mxml and the other Events and Commands that have been added to the CairngormLogin project.