Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
ColdFusion Builder, based on the Eclipse workbench, is Adobe’s first dedicated development environment for programmers of ColdFusion-based Internet applications. ColdFusion Builder Essential Training, with author Dan Short, is designed to teach both new and experienced ColdFusion developers how to configure servers and services, generate data-aware components, and create custom extensions. Exercise files accompany the course.
Extensions use handlers or regular old ColdFusion pages to accept the user's input and do all the necessary processing for the extension. The user inputs are sent as a form field, which contains a block of XML. So, it takes a small bit of processing to make the data usable in your ColdFusion pages. Let's start by building our handler to dump exactly what's sent to the extension, so we know what we are dealing with. So, in our handlers directory, we will open up the index.cfm file. At the top, I am just going to dump out the entire form scope. Now, one thing you also need to do inside of your handlers is to make sure that debug output is turned off.
We will click OK, and here we can see the XML that gets sent to the handler. At the root, we have an event tag, which also has an IDE tag, and then a View tag depending on the type of contribution that we set up in our ide_config. The View tag will give you the project name and the location for the project, where the user right- clicked to execute the extension. The Resource tag inside that will tell you exactly which file or folder they clicked on to execute the extension.
So, if you need to take a particular action on the folder they selected, you will be able to grab that from the path attribute of the Resource tag. After the closing IDE tag, you then have a User tag, which contains all of the inputs that the user filled out and their values. This is what we are going to need to use for this extension in order to determine what replacements we need to make. So, let's start working with the XML to pull out just the pieces that we need. So, I will close the extension. So, in my handler, I am going to start by pulling out all of the user inputs.
So, I am going to parse the IDEEVENTINFO field into an XML object and then use the XMLSearch function to pull out all of the input tags in the user node. This is going to give me an array of inputs. So, I am going to take my dump here, move it down, and then let's dump out exactly what the userInputs is returning. I will save my handler and we will execute our extension once more. Fill out the bare minimum of fields.
Click OK. It will execute my ColdFusion code, and here we can see my array. So, inside each array node, I have an input that has a name and a value. mailPassword is blank, but as you can see here, my fileLocation is not blank. My fileName is test.cfm and my mailTo has my e-mail address. So, we will close that and we can go on to the next portion, which is to create a usable structure of fields. So, an array isn't easy to reference via names.
So, if I wanted to get just the file location, I have to loop through my array and figure out which array node has it and then pull out the value and go through a bunch of rigamarole to find exactly what I want to use. So, these next few lines of code is going to loop through our array, userInputs, and it's going to create a userData structure with the name and value. I will make this a little bit bigger, here we go. With the name and value of each of the userInputs. So, this is going to give me something on the lines of userData.filename.
So, let's move our dump once more and take a look at that. Unfortunately, part of building extensions is going to be lots of dumping of variables and rerunning of extensions, in order to make sure that you have exactly what you need. So, we will fill out our dialog again. You will get really good at this part. Now we have a nice structure that has our fileLocation, our fileName, and our mailTo.
So, these few lines of code, from Line 2 to Line 10, will allow you to take all of the inputs and convert them into a usable structure that you can then reference through the rest of your handler code. You can take that eight lines of code and reuse it in any extension you build, in order to easily get to the user input data. So, the next block of code isn't exactly extension-specific, but it is going to take care of all the replacements that we need in our formTemplate. So, here, I will make my file a little bit bigger. We are going to actually read in our formTemplate and take note of the fact that I am using the ExpandPath function, because I don't actually know where my formTemplate is going to exist when the user installs this extension.
They can put it anywhere on their hard drive or on a remote server and I have no idea where that file is actually going to live. So, when you are building your extensions, make sure that you make them flexible enough that the files they are referencing can live anywhere. So, once I have written my formTemplate .cfm, I am just going to loop over my userInputs array, and for each item in that array, I am going to replace the field name, for example, the Mail Server, mailTo, and Subject, and replace them with their appropriate value.
Then after we are all done doing the replacements, we will actually write out the file to the fileLocation the user specified, and the fileName that they typed in. We are just going to use the formTemplate as the output for that file. So, we have one last thing to do, which is to show the user a response and let them know that everything was successful. So, now I will insert my last snippet. This bit of ColdFusion code determines that the output for this file is going to be of an XML MIME type, and inside of my cfoutput tags, I have a response tag, an ide tag, and a dialog.
So, what this does is tells ColdFusion Builder that I want to show a dialog that's 500 pixels wide by 300 pixels tall and I want this to be the content of that dialog. So, all I am telling the user is that a new file has been written to and I am giving them back the fileLocation and the fileName, so that they know exactly where that file got written to. So, the last thing I will do is get rid of my cfdump tag. We will save my CFM file, and we will go back and run this extension one more time. So, this time I am going to complete the entire UI.
We will put our file inside of the Chapter 8 folder. We will name it contact.cfm. We will give it a server address, mymailserver.com. Give it a username of dan, and a password of password. We will say it's the 'Contact Form Results' for the subject, and where we want it to be e-mailed to. Click OK. Here's our UI that we wrote.
A new file has been written to and it gives me the exact location for that file. Click Close. Go to the Chapter 8 folder. We will open up our contact.cfm. As we can see, here in the cfmail tag, there is the e-mail address, the subject, the server, my username, and my password. That's it. You have now built an extension UI and hooked it directly to a ColdFusion handler. Now you just need to take these files and repackage them in a zip and you are ready to go.
You can now venture out into the wild to build your own extensions. You can also find a collection of ColdFusion extensions at www.riaforge.org by clicking on ColdFusion Builder Extensions. That way, you don't have to build something that someone else has already built for you.
There are currently no FAQs about ColdFusion Builder Essential Training.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.