This is a going to be a real short post but I think its a great little time saver. In ColdFusion 9.0.1 they added a second argument for the entityNew function. Now you can pass in a structure of properties and the setters will be called when the entity is instantiated. So before we had to write code that looked like this.
And now we can write code that looks like this.
One way to debug Hibernate is to log the generated sql, another way is by enabling live statistics. By default ColdFusion has live statistics disabled and for good reason. This is not something you want running in production and its only meant for development. The easiest way to get statistics out of the Hibernate engine at runtime is the Session Factory. Fortunately for us ColdFusion has exposed this to us by using the ormGetSessionFactory() method.
If you run the following code you will see all of the different statistics methods exposed to you.
There are statistics for things like
Global Statistics
Entity Statistics for a particular entity
Collection Statistics for a particular collection role
Query Statistics for SQL & HQL queries
Second Level Cache Statistics for detail runtime information about a particular region in the optional second-level cache
If you try and call any of these methods right out of the gate they are not going to work. If you remember I said earlier that statistics are not enabled by default, but we can enable them pretty easily.
Now when you call any of the stats methods we will start to see some data. There is also a continent method to find out if they are enabled.
Finally we could take this and add some debugging output to application by using the on request end method in our application. The hibernate_stats.cfm could have some output with any or all of the statistics methods.
In a perfect world of software development where a database is involved the naming conventions for tables and columns are standard. As you are aware that is not always the case. Sometimes we deal with really long or unconventional naming strategies. Fortunately for us hibernate has a way of dealing with this and ColdFusion, like everything else it does has made this really for us to use.
Let's pretend for our demo here that we are doing some work for ABC Company and that have this weird naming strategy where all of there table names are prefixed with tbl_ and all of their column names are prefixed with col_.
I think you get the idea. If we were to create an entity based off of this table we would end up writing code that looked like this.
I realize this is a bit old but there is a purpose to my madness. While I was at cfunited I was talking with Dan Wilson and I told him what a great job they did with posting the video recordings for NCDEVCON 2010. I really hope more conferences can start taking this approach. I don't remember who else was in the conversation but I remember them not knowing these videos were available so I thought I would share the link with anyone who didn't realize they were out there.
Last week while I was at cfunited I got a comment on an old post that went a little something like this.
You were working on an example to show how to click a row and show details. Is there anywhere I might see this example?
This should be pretty easy, lets go ahead and build this out. Before we get started lets take a look at what we are trying to accomplish here. We will have a grid on the left with our first and last name and when you click on a record it will populate on the right in our form.
The first thing we need to do is create the basic layout for our app.
For this example we are going to use the art gallery database that ships with ColdFusion. Here we are creating the query and the grid. What's important to note here that even though we are not displaying all of the records they need to be included in the grid. If we did not the columns would not be stored in the underlying ext data store.
Next we will create our details area.
At the end of all of this code we will use ajaxOnLoad to call a javascript method when the page loads. Basically all we are doing here is getting our grid object and adding a row click event listener to it. When we click on a row we are getting the record from the underlying ext data store. That record basically contains a record object. An easy way to see what the record is made up of is to log it to the console. Finally I just wrote a convenient method for setting the value of the input field.
So now we have our layout setup we just need to glue everything together.
I decided to make the code available for the cfunited mobile application. I will probably setup svn so I can actually update some of the code but for now I just threw up a zip of what I had on my local machine. First off you will need to download Sencha Touch and then adjust the paths to Sencha in the index.html. There are a bunch of bugs still in the software that I will try and get to when I get home. The code is not the greatest but I whipped it together last second and it works. Also If you want to pass along any notes or feedback on the code I always love hearing that.
I just finished my "Developing web applications for mobile devices" presentation and it was awesome. Coming off of yesterdays presentation that didn't go as well as I hoped I was happy that I had to redeem myself this morning. First off I had the 1st slot today at 10 AM and I really happy I was able to get up in time ;)
I was really happy to see a full crowd in the room this morning. There was standing room only in the room and I was pretty happy to find out they were in the right room! Anyways, here is the presentation along with all of the demo code. Click on the menu button to download the code.
Thanks to a couple attendees I have some pictures from the presentation.
ColdFusion 9 added some new functions for the html grid. I want to take a look at 2 of them today that will make your life a little bit easier. In this example we are going to create a grid and add a toolbar to the grid. In the toolbar we are going to add some buttons with event handlers.
First we need to create a grid to display our artists.
Then we use the ajaxOnLoad() method to call a function.
In ColdFusion 9.0.1 we have the ability to get the grids top toolbar. With the top toolbar we can now add elements to it. Finally we use another new function to show the toolbar.
And here is the final result
Just a side note, you can also do this for the bottom toolbar as well. Here is a list of all the new JavaScript functions for the grid.
I just wrapped up my 1st presentation at CFUnited. Thank you to everyone who attended it. I had some issues with it but hopefully anyone who attended still enjoyed it. If you click on the menu option you can download all of the code for the presentation.
Last night I was working on a Mobile application that gets is data via a web service. This web service returns JSON by turning a record set into JSON using the serlializeJSON() function that is built into ColdFusion.
Whenever I am dealing with JSON I like to validate it before I start using it in an application. A great resource for validating data is http://jsonlint.com/. The data I was trying to get just was not validating and we couldn't figure out why. It seem to keep complaining about the bio of the speaker. This data for this was produced by the end user. In the end Elliott realized that it was unsafe characters in the Bio that was throwing everything off. He used this code to fix the issue and the json was now validating.
I was going to explain how this works but my friend Ben Nadel has a whole post on this you should really check out. Basically all the code above is doing is removing an un safe character that does not fall in between the "safe" ascii codes of 1-127.