|
Blog redesign and a version update to BlogCFC 5.9.5 |
I've been running an older version of Blog CFC for a while now, so I thought it was well past due an update to the latest version. It seemed like a good time to give the site a lick of paint, so I have de- web 2.0'd it. At some point I got swept up in the curved corners and shiny gradients of Web 2.0ness, and now I just plain don't like it.
If you didn't know already you can get BlogCFC from RIA forge here: http://blogcfc.riaforge.org/. There seem to have been some nice tweaks in the last few versions, and it's nice to see a software application maturing.
In the process of redesigning the site I came across this recent survey of the installed user base for windows fonts. It is always risky for a developer to use a non standard font, so surveys like this are ideal. http://www.codestyle.org/css/font-family/sampler-WindowsResults.shtml
Also I had a little Photoshop help creating the image header. Here is a pretty painless Photoshop tutorial on "Fade Images in Photoshop Using Layer Masks", http://articles.sitepoint.com/article/photoshop-fade-layer-mask
Lastly I've added some Feedburner integration. Feedburner is a great way of consuming your RSS feeds, it adds a whole load of options, and allows you to push feed content out to other community sources, such as Twitter or FaceBook. It also provides stats, a la Google Analytics style, and its free (requires a Google account)! http://feedburner.google.com.
I think I took two things away from this redesign. Firstly, double check your CSS. The only real issues I had during the entire process were CSS related (thanks IE). Secondly index your database properly. I'm not sure if the previous install was indexed at all, or whether the new version just has better indexing in the installation scripts, but the performance difference is notably quicker!
|
Pre loading object (CFC) references in your Application.cfc |
One of the best practices that I've been using more and more is ColdFusion's ability to add CFC object references to scopes. By this I mean that it is possible to create a shorter friendlier scoped variable that you use to reference your CFC's.
In your Application.cfc you can map out all your CFC references, this gives you a much shorter variable name to type each time, and it caches the CFC.
2
3<!--- scope out all the objects as application level vars --->
4<cfset application.formObj= createObject('component','dir.objName ')>
5<cfset application.siteObj= createObject('component','dir.objName')>
6<cfset application.mailObj= createObject('component','dir.objName')>
7<cfset application.config=createObject('component','dir.objName').getConfig(id=N)>
8
9</cffunction>
Put any references like this in the 'onApplicationStart' function. You do not need to lock the scope in this function, and if the code within it does not run successfully then it does not continue running the application. It will try again on the next page request.
The caching functionality here is great, not only will Coldfusion create a handy short name for CFC, but it will actually run through the code, and stop on any errors. If you deliberately introduce a code error into one of your objects you will see the Application halt and show you the error. For me this is reason enough to move all my business logic into CFC's. This essentially means that it is not possible for a user to get part of the way through a application and find an object based error.
Using this in conjunction with a framework such as FuseBox allows you to load, parse and cache the CFC object, all before your actual display layer has been invoked.
The example below uses the FuseBox function 'onFuseboxApplicationStart' of starting an Application.
2 <cfset super.onFuseboxApplicationStart() />
3<!--- scope out all the objects as application level vars --->
4
5<cfset application.formObj= createObject('component','dir.objName ')>
6<cfset application.siteObj= createObject('component','dir.objName')>
7<cfset application.mailObj= createObject('component','dir.objName')>
8<cfset application.config=createObject('component','dir.objName').getConfig(id=N)>
9
10
11</cffunction>
Changing the 'fusebox_parameters.mode' value allows you to set this caching at an environmental level, so no caching for development, or caching for live
2Or
3<cfset FUSEBOX_PARAMETERS.mode = "production">
|
What does "Invalid Label" mean in a JSON response, and how can I fix it? |
I recently build an application that returned a JSON object of data based on a select field value. Whilst I was building this I encountered an error using the JavaScript eval() function on my JSON response. I am using the eval() function to parse a string from my JSON response, but firebug is showing a JavaScript error of "Invalid Label".
This is the code:
2 jsonResponse = eval(data);
3 var src = jsonResponse.DATA;
4 });
After having a Google around it appears that the eval function is interpreting the first item in the JSON response as a label, rather than data. By changing the code like this:
We are forcing eval to recognise the data as variable data. Now the JSON to string translation works.
|
Creating an image preview using JQuery and a select form field |
This article will deal with a user choosing a value from a Select field, and that selection being passed to a JQuery handler. The JQuery handler will perform an AJAX request to a CFC, which will return a JSON value (URL String) that we will use to populate an img html tag.
In this way when you select different options from the select field drop down, the image changes inline, without any page reloads.