Viewers: in countries Watching now:
In ColdFusion 9 New Features, author and developer Dan Short has gathered together the important updates and improvements in this dynamic web application. Dan showcases the new ColdFusion Builder application throughout the course, using it to work through the new language and CFScript enhancements in this release. He shows how to use the new Server Manager to compare servers and create server groups, as well as monitor server health through notifications. He also explains the new integration with Office applications, building Excel, Word, and even PowerPoint files on the fly from ColdFusion. Finally, he covers the important new Object Relational Mapping feature and how to use the built-in Flash Player. Exercise files accompany this course.
One of the pains in building object- oriented ColdFusion and particularly Smart Value objects is dealing with all the getters and setters you need to write in order to protect your properties from malicious data. ColdFusion 8 made this easier by adding the OnMissingMethod() method but that still involved rolling your own solution to deal with building implicit getters and setters. ColdFusion 9 solves this by providing implicit getters and setters on all properties defined by the cfproperty tag, if you want to use it that is.
This offers huge benefits in coding time. So to demonstrate this in the Chapter 4 folder, I have a few files. First I have person.cfc, and gettersandsetters.cfm. Let's take a look at the person's component first. So in here I have defined some cfproperty values. I have Firstname, Lastname, Address, City, State and Postalcode. I have an init() method, which allows me to fill the object with data on the initialization. And then I've hard-coded some getters and setters for the state.
So let's open gettersandsetters.cfm and see what that looks like. In here I am instantiating a new copy of the person object and I'm setting the state to Texas and then dumping the object itself. So if we preview that file, we can see that in here I have my methods, my SETSTATE, my INIT, and my GETSTATE and we can see my properties are The Great State of Texas. Now if I wanted to create getters and setters for the rest of my properties, I would need to either hard-code those or I would need to build my own custom solution using the onMissing method.
In ColdFusion 9, however, I simply need to go to cfcomponent tag and add accessors = true. Now if I go over here to my gettersandsetters.cfm and reload this page, you will see that a few things changed. First all my properties ended up with their default values, as I would expect them to, and in the methods I can now see that I've getters and setters for every single property in my file. Now I don't have to write any new code. All I had to do was add accessors = true.
So if I go back to the source code, I can now do cfset MyPerson.setFirstName to Dan, and let's set the name Short. And I will preview my file again and we can see that the first name and the last name have been set to Dan and Short appropriately. What if I don't want an implicit getter and setter on something? Well one way to get around that is to add my own.
You will notice that it's still using my custom built getter and setter for the state. It's still saying 'The Great State of' instead of just Texas. Also I can get rid of a getter and setter on a particular property by doing this. I can say setter = false and getter = false. Now the implicit getter and setter for last name will not be built. So if I go back over here and reload this page, I am going to get an error.
Because I've told it not to build the implicit setter for last name, I am now receiving an error on that particular method. If I get rid of these, gp back and load my page again, everything is back to normal. Now if you want to do type validation, the implicit getters and setters will honor your types here. So for example if I want to say that my postal code has to be numeric, I can add numeric on here and if I attempt to set that, let's go over here, MyPerson.SetPostalCode and we will just set it to ABC, which is obviously not numeric, and load my page.
I will get 'The value cannot be converted to Numeric.' So if you need to do any special validation on a particular value, you are going to need to roll your own getters and setters. If you can rely on ColdFusion's simple type validation then you don't have any more work to do. So using implicit getters and setters on your ColdFusion 9 objects is absolutely the right way to go. It will make coding faster, more secure and easier to deal with in the end.
There are currently no FAQs about ColdFusion 9 New Features.
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.