Tuesday July 1, 2008 12:00 AM
Word Count:
1152
Now that I am working a lot more with jQuery I thought I would start posting little examples of why I enjoy using it so much. If you are looking for a full on beginner or selective tutorial you should head over to the tutorials section on the jQuery site, it is packed with great stuff. This first example is a short one but to me is the main reason I have been using jQuery so much lately. Just keep in mind when I am going through these examples that I am no JS expert so there may be better ways to accomplish the task at hand.
Everyone has dealt with a select box (drop down) at one point or another right? One thing I really hate about JS is how much code I have to write just to accomplish what should be a simple task. Here is the way I would of done it in the past. In our example we have a list of developers in a select menu. We explicitly set an onChange event handler (not a good practice more on that another time) that calls our onSelectChange method. The problem now is that you have to grab the element from the dom, find the selected index and write all this code to get the values and text. I just don't have fun writing this and you can probably see why. If there is a better way that is my fault and while this would work its just no fun for me.
Now on to the fun part. The first thing we need to do is include the jquery library and create a ready function. We also have our list of developers and our goal is to write out what developer the user selects every time the selection changes.
The first thing we need to do is to notify our application that the user changed their selection. To do that we can use a jquery change event. To use this event we must first have a jquery object. This is really where the beauty of the code lies, almost everything is returned as a jQuery object. By selecting our developer select we simply attach an event and pass in the name of the function we would like to call when the event occurs.
Now we can write our method that handles the actual logic of our application. Remember all that code we wrote earlier, it was ugly right? This to me is a better approach, first you can get the selected option using the option:selected selector. This will return to us a jQuery object and we can get what we need by using the val() and text() attributes. The html() method in this case sets the contents of an element.
There is a link below for a live demo of this. This was just a quick example of why I enjoy using jQuery. The code is clean and I am never guessing what some method returned to me (object/string/date) because I will almost always get back a jQuery object. If you have any questions about this example let me know and for you more advanced users I got some good stuff in the pipe so stay tuned.
Select Demo
Monday June 30, 2008 9:21 AM
Word Count:
272
Lately I have been doing a lot more development using jQuery and I am loving it. If you think back to when you first started using ColdFusion I would imagine we have a similair story. Some of you may have read an article somewhere about this great language but I bet most of you may have a story closer to mine. I was getting into building dynamic sites and a friend told me you really need to pick up ColdFusion. It makes complex things very easy and cuts down on development time. I thought perfect, this is exactly what I need, more time to hang out with friends.
Fast forward to today and I find myself in the same position. I have used jQuery before but for smaller projects. Now that I am getting deep into some project I can truly understand what the hype it about. So I am doing today what someone did for me awhile back and that is trying to push some people in the right direction. If you have not had a chance to check it out then you really need to. Just as ColdFusion it make really easy things simple and what a time saver on code. Over the next couple of weeks you are going to see a lot of examples from me (I have at least 6 now) that I am going to walk you through. You may have seen most but for those who have not it will hopefully open up your eyes.
Wednesday June 25, 2008 9:45 PM
Word Count:
103
I had the change of meeting Ben Nadel at CFUnited. It was really good to finally meet him after all of this time and a put a face with his work. Funny enough he mentioned to me that he really liked the crowd background I had on my old site. I am already getting bored with the new site so I switched out that background. If you head to the main page of the site you can see the crowd background in large. I am not sure what other requests I can do but give it a try ;)
Wednesday June 25, 2008 1:17 PM
Word Count:
107
I recently updated to Firefox 3 and so far I am loving it. One of the essential tools to anyone in my position is Firebug. I installed the new beat 1.2 and I just could not get it to open. The installation was fine but every time I try to open firebug nothing would happen. This is actually a problem with ColdFire that I had installed. If you are having a similar problem just remove ColdFire and it should work fine. I am a big fan of ColdFire so as soon as they get things working I will be upgrading.
Wednesday June 25, 2008 9:29 AM
Word Count:
100
Probably not but I am apart of the new CFConverstations podcast. I am no episode 2 but that is no reason to pick up the podcast. The podcast has some really good content and 3 of the first 4 episodes were done right from CFUnited. There were some issues with audio because it was everyone huddled around a mic but Brian is doing is best to clean up the issues. I know some of the interviews Brian has lined up for the future and all I can say is stay tuned for great things to come.
Wednesday June 25, 2008 12:36 AM
Word Count:
41
Have you ever wanted to find out if an array is a single dimension or a double(matrix). There is a handy method in the coldfusion.runtime.Array class for doing just that. The following will output 2.
Tuesday June 24, 2008 11:51 PM
Word Count:
1930
I have been having a lot of fun lately digging around the internals of the Adobe CF Server. With my new found knowledge I thought I would dig around structures. So how can you find out what the implementation of a structure is? Well first off you need to find out the name of the class and to do this it gets pretty tricky.
Looking at this we can tell the class for the struct is coldfusion.runtime.Struct, as I said it can get pretty tricky (ha). So what that does is return back an the class Object which has some pretty handy methods in it. There are methods that can tell you what the package is, what the super class is as well as methods, fields & constructors. If we look at the following code we can see that there are easy ways to output all of this information.
//methods
methods = class.getMethods();
writeOutput("Methods" & "
");
for(x = 1; x LTE arrayLen(methods); ++x) {
writeOutput(methods[x] & "
");
}
writeOutput("
");
If we run the previous code we get the following output.
Class: class coldfusion.runtime.Struct
Superclass: class coldfusion.util.FastHashtable
Package: package coldfusion.runtime
Fields
public static final int coldfusion.monitor.memory.MemoryTrackable.NO_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.LOCAL_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.ARGUMENTS_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.THREAD_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.PAGE_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.THIS_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.REQUEST_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.SESSION_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.APPLICATION_SCOPE
public static final int coldfusion.monitor.memory.MemoryTrackable.SERVER_SCOPE
Constructors
public coldfusion.runtime.Struct(int)
public coldfusion.runtime.Struct(coldfusion.runtime.StructWrapper)
public coldfusion.runtime.Struct()
Methods
public java.lang.Object coldfusion.runtime.Struct.clone()
public synchronized java.lang.Object coldfusion.runtime.Struct.get(java.lang.Object)
public synchronized java.util.Map coldfusion.runtime.Struct.duplicate(java.util.IdentityHashMap) throws java.lang.IllegalAccessException
public java.lang.Object coldfusion.runtime.Struct.writeReplace()
public java.util.WeakHashMap coldfusion.runtime.Struct.getStructWrapperMap()
public static boolean coldfusion.runtime.Struct.IsStruct(java.lang.Object)
public static boolean coldfusion.runtime.Struct.StructAppend(java.util.Map,java.util.Map,boolean)
public static boolean coldfusion.runtime.Struct.StructClear(java.util.Map)
public static java.util.Map coldfusion.runtime.Struct.StructCopy(java.util.Map) throws java.lang.Throwable
public static int coldfusion.runtime.Struct.StructCount(java.util.Map)
public static boolean coldfusion.runtime.Struct.StructDelete(java.util.Map,java.lang.String,boolean)
public static java.lang.Object coldfusion.runtime.Struct.StructFind(java.util.Map,java.lang.String)
public static coldfusion.runtime.Array coldfusion.runtime.Struct.StructFindKey(java.util.Map,java.lang.String,java.lang.String)
public static coldfusion.runtime.Array coldfusion.runtime.Struct.StructFindValue(java.util.Map,java.lang.String,java.lang.String)
public static boolean coldfusion.runtime.Struct.StructInsert(java.util.Map,java.lang.String,java.lang.Object,boolean)
public static boolean coldfusion.runtime.Struct.StructIsEmpty(java.util.Map)
public static coldfusion.runtime.Array coldfusion.runtime.Struct.StructKeyArray(java.util.Map)
public static java.lang.String coldfusion.runtime.Struct.StructKeyList(java.util.Map,java.lang.String)
public static java.lang.String coldfusion.runtime.Struct.StructKeyList(java.util.Map)
public static coldfusion.util.FastHashtable coldfusion.runtime.Struct.StructNew()
public static coldfusion.runtime.Array coldfusion.runtime.Struct.StructSort(java.util.Map,java.lang.String,java.lang.String,java.lang.String)
public int coldfusion.runtime.Struct.getScopeType()
public coldfusion.monitor.memory.MemoryTrackerProxy coldfusion.runtime.Struct.getMemoryTrackerProxy()
public void coldfusion.runtime.Struct.setMemoryTrackerProxy(coldfusion.monitor.memory.MemoryTrackerProxy)
public java.util.Iterator coldfusion.runtime.Struct.valuesIterator()
public synchronized java.lang.Object coldfusion.util.FastHashtable.put(java.lang.Object,java.lang.Object)
public synchronized void coldfusion.util.FastHashtable.clear()
public synchronized boolean coldfusion.util.FastHashtable.contains(java.lang.Object)
public synchronized boolean coldfusion.util.FastHashtable.isEmpty()
public synchronized void coldfusion.util.FastHashtable.putAll(java.util.Map)
public synchronized int coldfusion.util.FastHashtable.size()
public synchronized java.lang.Object coldfusion.util.FastHashtable.remove(java.lang.Object)
public synchronized java.util.Enumeration coldfusion.util.FastHashtable.elements()
public synchronized java.util.Enumeration coldfusion.util.FastHashtable.keys()
public synchronized boolean coldfusion.util.FastHashtable.containsKey(java.lang.Object)
public int coldfusion.util.CaseInsensitiveMap.hashCode()
public boolean coldfusion.util.CaseInsensitiveMap.equals(java.lang.Object)
public java.lang.String coldfusion.util.CaseInsensitiveMap.toString()
public java.util.Set coldfusion.util.CaseInsensitiveMap.entrySet()
public java.util.Collection coldfusion.util.CaseInsensitiveMap.values()
public java.util.Set coldfusion.util.CaseInsensitiveMap.keySet()
public boolean coldfusion.util.CaseInsensitiveMap.containsValue(java.lang.Object)
public java.util.Map coldfusion.util.CaseInsensitiveMap.duplicate() throws java.lang.IllegalAccessException
public final native java.lang.Class java.lang.Object.getClass()
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
Now we can't really see the code but we can see what methods are available to us. The first thought is well is there anything I really care about? That was my first thought as well so lets go through a couple things I found.
The first thing i noticed is that there was a method name hashCode() that returns an integer. Usually a class will override the equals method to allow for comparison of objects. So usually if the objects are equally these hash codes are the same. Have your ever needed to see if two structures contained the same keys/values? Well using our new knowledge this should be possible. The following tells us that our structures are equal, if you change the 2nd loop to a max of 20, they come out not equal. Also its helpful if you check out the hashCode() for each as they will be the same here.
EqualNot Equal
Another useful method is the toString method. Most objects override this method and this one gives us a great print out.
If we run the code above we get a nice print out that looks like this.
{1={1.0},2={2.0},3={3.0},4={4.0},5={5.0},6={6.0},7={7.0},8={8.0},9={9.0},10={10.0}}
The final one is just something I thought I would throw out. I have not found an improvement in performance but its there so I thought I would show it to you. If you wanted to print out all of the values you would usually just loop over the collection and print out each keys value. If you look at our methods list there is one called valuesIterator(). This method returns us an iterator that has 2 handy methods for looping. Here is a quick example of how to run over the values. Please remember this is just here for fun.
iterator = myStruct.valuesIterator();
while(iterator.hasNext()){
writeOutput(iterator.nextElement());
}
While some of you may question my madness I really have no answer. I saw a wonderful presentation at CFUnited only to come home on a treasure hunt. You should be able to start looking around on your own, happy hunting!
Monday June 23, 2008 9:53 PM
Word Count:
94
I am sorry If I am telling folks stuff they already know but I am having tons of fun digging around. So have you ever needed a quick way to see whats going on in every scope? I think I have written debug functions before that dump out a bunch of scopes like application, session and CGI. Well if you want a quick way to see what is living in every scope there is actually a very easy solution. I am on ColdFusion 8.0.1 by the way.

Monday June 23, 2008 9:35 PM
Word Count:
305
Every since watching Elliott Sprehn's presentation on the "Internals of the Adobe CF Server" presentation at CFUnited I have become a curious hunter. Today I was playing around with the page context and I found a cool little gem. So everyone has probably needed a random number at some time for whatever reason and you have probably turned to the built in ColdFusion function randRange. While this works great and I am not certain and this is just a guess but I would think that uses java.util.random class in Java. Today I found out that that class is already available to you as part of the page context. The cool thing is there are some other methods in there that could be a big help to you. If you have ever needed a random boolean this is perfect for you. So here is a little code you can play with and the dump of the random class. Of course you could already do this by invoking the java class but why do it if its already there. If you want to learn more about the different methods just check out the api.

Sunday June 22, 2008 8:47 PM
Word Count:
1044
There are two major features I have yet to talk about and I have saved the best for last. First we are going to talk about the new AIR Integration. The more and more Flex/AIR code I start writing I see places where tighter integration would definitely help adoption rates. ColdFusion is the perfect back end for AIR applications and AIR is an ideal client for ColdFusion. Ben pointed out the with LCDS data sync is currently available but its a very manual process right now and he said that it was there job to streamline the process. Adam showed off some demo code that he said they were just playing around but looked amazing to say the least. The idea behind the code is that your AIR application could be online, make a connection to the server and write data to that datasource but if the application went offline it could write to a local database (SQLLite). Right away the wheels in my head started turning and I thought wow this would be great for blog software (BlogCFC) in an application where you could write a bunch of articles on a plane ride and sync (post) them when you get off. This is the code, please remember this is just protype and not the actual implementation.
The final feature I want to talk about and probably one of the biggest is native ORM via Hibernate. If you have never heard of ORM it stand for Object Relational Mapping. If you want to learn more there are 2 projects for ColdFusion in the ORM market Transfer & Reactor. While its possible to use hibernate today its a very manual process and like everything else in ColdFusion they want to make it as easy as possible to use. So what is hybernate, this a quick intro straight from the site.
Hibernate is a powerful, high performance object/relational
persistence and query service. Hibernate lets you develop persistent
classes following object-oriented idiom - including association,
inheritance, polymorphism, composition, and collections. Hibernate
allows you to express queries in its own portable SQL extension (HQL),
as well as in native SQL, or with an object-oriented Criteria and
Example API.
Databases are the core of all ColdFusion applications and integrated ORM in Centaur will dramatically simplify data integration. The basic idea is that by using hibernate all you would have to do is tell a cfc the datasource and turn orm on it will create all of the sql needed for you. This means for basic crud applications you will no longer have to go in and write/generate 4 methods for every table in your database. Here is a quick example of the code Adam showed. This is the least amount of code you need to persist a cfc to the database.
Here is an example of using the built in ORM. You will notice that we have all the implicit getters/setters and you would be able to call the save method that you never wrote!
A pretty cool feature that Adam showed is the configuration file for hibernate. They use pretty much the same configuration file as hibernate. If you were to go ahead and dump the object straight to screen you would see all of the getters/setters along with all of the component methods. With everything else they are adding your code will still work the same and this is only an option. If your not a fan of ORM than don't bother using it.
I have to admit that I have never used hibernate so I may try and download it and hook it into ColdFusion so I can how it works. I have used both Reactor & Transfer before and they are both great products so if you have not used an ORM yet I would check it out. Ben also stated that if you have ideas on how this should work / implementation / features then you should blog about it or even email them about it. These are 2 really great features and I am looking forward to seeing what the community thinks about it. I also learned from the keynote that ColdFusion 9 will ship in 2009 so we are not that far away. I am also curious about something else Adam mentioned, he said that it is a small peice of a much bigger puzzle. Any ideas on what he is talking about?
More Entries