Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The heart of any good development IDE is its code completion engine. As you saw on the previous chapter, you can do a ton of customization around how CF Builder writes your code. So, let's put some of that to use, by working on a simple login application. In the Chapter 5 folder, I'm going to take these three files from the begin directory and we'll put them in the Chapter 5 directory. Open up these files and take a quick look at what we're starting with. First off, my Application.cfc.
I just have an onApplicationStart method and an onRequest method, which we'll fill out as we continue on through this video. My index page is where I'm going to keep all of my trade secrets about my Art Gallery. On my login page, I have the start of some code of a cfparam at the top and I've started my login form. I have my username field. I just need to add the password field. Now to begin, let's go to the Application.cfc and we'll finish up this file. The first thing I'm missing in my Application.cfc is the cfapplication tag.
So, I'm going to start by adding that tag here at the top and I can just start typing cfap, and as I type, the code hints will eliminate tags that don't match what I'm typing. So, I've got cfap and I only have cfapplet and cfapplication as valid selections. I can then click on the tag that I want, or use my arrow keys, select it and press Enter and CFBuilder will add a space after the tag and close it for me and immediately pop up all of the attributes available for that tag.
Off to the right-hand side, I can see a tooltip that tells me exactly what that attribute does. If I use my arrow keys, I can scroll down through the attributes and the tooltip will change to show me exactly what I need to enter. So, we'll choose name, and once I have the attribute selected, press Enter, the attribute will get added as well as the equal sign and my quotes. I'll type the name of my application, press the arrow key to move past the quote and press the Spacebar again, and all of my attributes pop back up.
But the name attribute is missing since it's already applied to the tag. Now for a login application, I need to enable sessions, so I can keep track of whether or not a user has successfully logged in. So, we'll scroll to the bottom, choose sessionmanagement. CFBuilder adds the equal sign and the quotes for me and then because sessionmanagement is a true or false value, it gives me the two possible entries for that value. I can choose which one I want, press Enter and then CFBuilder adds a space and pops up the attribute code hints again.
So, as you can see, once you get rolling, you can really add tags and attributes very, very quickly, by letting ColdFusion Builder finish your work for you. So, we'll close the cfapplication tag. Now instead of the cfapplication tag, I actually like to use the this scope in my application cfcs. Let's replace the cfapplication tag with this scope variables. I'll press Shift+Enter to move down to a new line and then Command or Ctrl and Shift+= to add in a cfset tag, type this and press the period and CFBuilder will show me all of the appropriate attributes for the this scope, inside of the application.cfc.
You'll notice that I don't get any of the tooltips for the attributes, but I do still get all of the correct attributes. The reason is that CFBuilder sees the this scope as a variable scope and scopes don't have attributes like tags do. With the cfapplication tag, it's looking at tag attribute, so it knows exactly what everything is. Now, let's go ahead and add the name attribute and put in the same thing, CFBEsstCh5, and I forgot to put my double quotes around my name, but if I hold on the Shift key and highlight all of my text, then press Command+Shift+Apostrophe on my keyboard, it will surround the code with the double quotes.
I'll press Shift+Enter. We'll go to the next line, Command+Shift +=, this.sessionmanagement = true, and I can press the Shift+Enter again and go on to the next attribute very, very quickly. Now that we have our application set up, I'll go up to line 3 and I'm going to delete this line by pressing Command+D or Ctrl+D on Windows. And that would delete that line. Now I need to add my onSessionStart method, so that every time a user session begins, I can set a variable that determines whether or not that user has logged in.
So, I'll go to the bottom of my file, and instead of typing out all the code this time, I'm going to use the Tag Wizard, which is right here in the cfml toolbar. So, I'll click Open Tag Wizard. I can choose the version of ColdFusion I'm coding against. In this case, ColdFusion 9, and I'll type in the name of the function, cffunction, press Enter and it shows me my tag right here. I can select my tag and click OK and CFBuilder will show me all of the attributes that are available on this tag. I can just tab through all of the attributes and set the proper values.
In the access dropdown, I'll press the down arrow to get the menu to expand. I'll choose public, press Enter. Tab down to the name. This one is called onSessionStart. Our output is going to be false, returnformat will be blank, the returntype will be void. roles, securejson and verifyclient, we can leave blank and click OK. CFBuilder then adds a cffunction tag for me and leaves all of the blank attributes off of the tag. So, it only added attributes that I actually provided values for.
Now I don't like the way it's formatted, because it's all flush left. So, if I click and drag to select these two lines, I don't have to select the entire line. I can then press Tab and indent both lines. If I click anywhere in the middle of the line and press Tab, it will actually just insert a Tab character. but if I have any text selected in a line, it will indent and outdent by pressing Shift+Tab. So, we have two more things to do. I need to set a variable inside my onSessionStart and I actually need to render my page in the onRequest method.
I'll press Command+Shift and Enter, which will add a new line above my closing cffunction tag and place my cursor at the beginning of the line. Then press Tab, Command+Shift+= to add my cfset Session.Logged = True. Now in my onRequest method, I need to actually render the page that's being passed to the method. So, I'll do cfinclude template. After I press Enter and add the template attribute, I can click on Select File or Folder and actually browse to the file that I want to cfinclude, but in this case, we're actually using an argument passed to the onRequest method.
So, I'll press pound, type Arguments, period and CF Builder will show me all of the arguments for the current function that I'm inside. So, you'll notice it lists target page. I'll just press Enter, then close my cfinclude tag. We now know all the basics of CFBuilder's code completion engine. If for whatever reason you don't see code hints pop-up when you expect them to, you can always press Ctrl+ Spacebar to get code hints to appear. If you find that CFBuilder is doing something you don't want it to do, go back into your Preferences and tweak the settings to get things just the way you want them.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 105512 Viewers
56 Video lessons · 117171 Viewers
71 Video lessons · 86406 Viewers
131 Video lessons · 41306 Viewers
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.