We launched a new IT training category! Check out the 140+ courses now.

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

Writing components in CFScript

From: ColdFusion 9 New Features

Video: Writing components in CFScript

As I mentioned earlier in the course I'm not a huge fan of CFScript, but for those that are, this is the video for you. ColdFusion 9 now allows you to write CFCs entirely in CFScript, no tags at all, not even a CFScript tag. In this video, we are going to take an existing CFC and show you the pure CFScript version to show you the format of the component and a method definitions as well as the Javadoc Style of defining attributes and metadata for your properties and methods. So in the Chapter4 cfcs directory, we will open Person.cfc.

Writing components in CFScript

As I mentioned earlier in the course I'm not a huge fan of CFScript, but for those that are, this is the video for you. ColdFusion 9 now allows you to write CFCs entirely in CFScript, no tags at all, not even a CFScript tag. In this video, we are going to take an existing CFC and show you the pure CFScript version to show you the format of the component and a method definitions as well as the Javadoc Style of defining attributes and metadata for your properties and methods. So in the Chapter4 cfcs directory, we will open Person.cfc.

This is the same CFC we used in the previous video to show you the implicit getters and setters. Sitting right next to that is PersonCFScript.cfc. This is the exact same component written in CFScript instead of ColdFusion tags. So I am going to show you these two files side-by-side. Now, the first thing you should notice is that first off, there is no open bracket cf anywhere. Second, there's no CFScript tags surrounding the component. You can start a component in CFScript by simply typing component at the top.

You can put the attributes that you would normally put on the CF Component tag and open brace, and at the bottom you have your closing brace that denotes the end of the component. In between there, you put all of your properties and functions just like you would in any other regular CFC. Here on our CF Properties, we have basically just removed the open bracket cf from the property itself. We have our name, type, hint, all the same attributes you would use, but where we start to see differences is in the function definitions. If you take a look here, I have my init function.

So I have first off the access, whether it's public, private, or remote. The keyword function and then the name of that function and inside the parenthesis, I have a comma- separated list of all of my arguments. They have their type followed by the name and if it has a default value, you put equals and its default value. If it does not have a default value, you simply leave that off. If you want to make an argument required, then you type required in front of it. So I have a required string, FirstName with no default value.

I am going to remove that and down here on my getters and setters for the state, they will be exactly the same. A public function, setState, and it takes one argument called state, which is a string. Now, where things really differ is how you go about setting the metadata on your functions. Because ColdFusion allows you to have a whole bunch of metadata about functions, there's no good way to put them as attributes inside of this declaration. So what will you do is directly before your function definition you put a /** and then **/ again to close the Javadoc comment for this particular function.

The first lines inside that comment are the hint for the function. So here you can see it initializes any data in the object. Over here in my standards tag base when you will see the same hint, "initializes any data in the object." Then you can determine the output and return type by doing the @output, true or false, @return type and then the type that needs to be returned. Then for each of the arguments, you can put the @ symbol, the argument name and then the hint for that particular item.

So to show you that these are functionally equivalent, we are going to use the ColdFusion component browser. So we will switch over to Safari and we are going to go to localhost:8500/CFIDE/ componentutils/componentdoc.cfm. It's going to ask us for RDS password and here we can see all of our components on the server. In this case, we want to look at the Chapter4.cfcs and here I have my Person and PersonCFScript.

If I click on Person, we can see I have my path correct here. I have my hint on the CF Component tag. I have all of my properties. I only defined a hint on the Firstname property and on my init method, I can see the two line hint that I typed as well as each of the hints on the individual arguments. Now, if I click on PersonCFScript, they are almost exactly the same. They are not the same, because my PersonCFScript has accessors="true" on it. Let's go back over here and remove that and then reload this page and now they look exactly the same.

All my implicit getters and setters have now be removed. We can see the same hint at the top, the same hint on the properties. If I scroll down here, I can see the same hint on my init method and all the same hints on my arguments. While CFScript isn't my thing, it may very well be yours and this is a fantastic way to be able to write all of your components in pure CFScript. As far as I can tell, there are no performance improvements from using one over the other, however, if you're coming from a Java or PHP or other languages that only offers a script-based syntax, this will make it much easier for you to get involve with ColdFusion or potentially convince those people in your office that are still holding out migrating to move over to ColdFusion.

Show transcript

This video is part of

Image for ColdFusion 9 New Features
ColdFusion 9 New Features

36 video lessons · 2921 viewers

Daniel Short
Author

 
Expand all | Collapse all
  1. 4m 30s
    1. Welcome
      53s
    2. Using the exercise files
      3m 37s
  2. 7m 48s
    1. Adding managing and comparing servers
      5m 26s
    2. Monitoring server health
      2m 22s
  3. 22m 10s
    1. Setting the default data source and SMTP
      5m 6s
    2. Getting programmatic debugging and exception handling
      5m 54s
    3. Reviewing the new onCFCRequest method
      5m 29s
    4. Using ApplicationStop()
      2m 24s
    5. Working with Server.cfc and onServerStart
      3m 17s
  4. 17m 45s
    1. Using ternary and chained operations
      5m 46s
    2. Using New and Import
      4m 2s
    3. Reviewing CFScript enhancements
      7m 57s
  5. 20m 23s
    1. Building with implicit getters and setters
      4m 26s
    2. Working with LOCAL scope in functions
      4m 35s
    3. Serializing objects
      6m 6s
    4. Writing components in CFScript
      5m 16s
  6. 19m 27s
    1. Getting started with ORM
      5m 51s
    2. Logging ORM activity
      2m 13s
    3. Saving objects to the database
      6m 10s
    4. Defining table relationships
      5m 13s
  7. 16m 59s
    1. Caching page fragments
      5m 29s
    2. Managing the cache
      4m 48s
    3. Working with in-memory files using VFS (RAM disks)
      6m 42s
  8. 12m 39s
    1. Working with Excel spreadsheets
      4m 56s
    2. Working with Word documents
      4m 4s
    3. Working with PowerPoint presentations
      3m 39s
  9. 28m 58s
    1. Loading Google maps with markers onto a page
      4m 53s
    2. Adding a Flash movie with the built-in FLV player
      2m 14s
    3. Using multi-file upload control
      6m 7s
    4. Building a progress indicator
      3m 37s
    5. Working with accordion layouts
      3m 18s
    6. Showing information with data grid enhancements
      5m 1s
    7. Informing users with Confirm Alert and Prompt dialog boxes
      3m 48s
  10. 9m 8s
    1. Accessing IMAP accounts
      6m 31s
    2. Working with the new array functions
      2m 37s
  11. 15s
    1. Goodbye
      15s

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 9 New Features.

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 preferences from 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.