Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Building the handler

From: ColdFusion Builder Essential Training

Video: Building the handler

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.

Building the handler

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.

If you are using debugging output on your local development machine, all of the JavaScript and extra CSS that get sent to the extension will mess up the display. So, you need to make sure that at the top of every extension, you have your showdebugoutput set to false. Now that we have that done, let's run our extension. So, I am just going to fill out the bare minimum of fields here so we can get on to the next portion. We will choose where to save the file to, the name of our file, and our e-mail address.

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.

Show transcript

This video is part of

Image for ColdFusion Builder Essential Training
ColdFusion Builder Essential Training

40 video lessons · 3858 viewers

Daniel Short
Author

 
Expand all | Collapse all
  1. 7m 48s
    1. Welcome
      59s
    2. Installing ColdFusion Builder
      2m 20s
    3. Installing ColdFusion Builder as a plug-in
      3m 18s
    4. Using the exercise files
      1m 11s
  2. 17m 42s
    1. Workspace overview
      2m 25s
    2. Organizing your workspace
      6m 19s
    3. Adding and selecting workspaces
      2m 53s
    4. Installing and managing plug-ins
      6m 5s
  3. 12m 12s
    1. Creating projects
      2m 11s
    2. Importing projects
      2m 48s
    3. Creating project working sets
      2m 23s
    4. Managing projects
      2m 22s
    5. Linking folders
      2m 28s
  4. 23m 2s
    1. Configuring and managing ColdFusion servers
      6m 26s
    2. Using the Services Browser
      4m 15s
    3. Using RDS Dataview and Fileview
      4m 52s
    4. Using FTP
      7m 29s
  5. 18m 10s
    1. Creating editor profiles
      2m 6s
    2. Using Code Assist
      5m 43s
    3. Setting code coloring
      4m 5s
    4. Using shortcut keys
      3m 5s
    5. Working with outlines and syntax checking
      3m 11s
  6. 37m 40s
    1. Using code completion
      7m 25s
    2. Using snippets
      9m 23s
    3. Using SQL editing and the Query Viewer
      5m 55s
    4. Working with components
      7m 27s
    5. Working with variable mapping
      2m 14s
    6. Navigating code and documents
      5m 16s
  7. 13m 12s
    1. Getting set up
      3m 50s
    2. Using the ColdFusion debugger
      5m 37s
    3. Watching logs with Tailview
      3m 45s
  8. 13m 8s
    1. Installing extensions
      4m 5s
    2. Using the CFC Generator extension for ColdFusion 8
      4m 52s
    3. Using the CFC Generator extension for ColdFusion ORM
      4m 11s
  9. 34m 5s
    1. Building a simple contact form extension
      3m 42s
    2. Creating user interfaces
      8m 55s
    3. Packaging the extension
      3m 55s
    4. Building the handler
      8m 10s
    5. Using the Builder extension
      9m 23s
  10. 25s
    1. Goodbye
      25s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed ColdFusion Builder Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.