Converting structkeys to lowercase

As you most probably know when you create a structure and don't quote the keys they are automatically converted to uppercase.


<cfset myStruct = structNew()>
<cfset mystruct.one=1>
<cfset mystruct.two=2>
<cfset mystruct.three=3>

When you dump it out you get:

and when you serialize it to json all the keys are also uppercase. This can be problematic since JS is case sensitive. You could create your structure with lowercase keys then serializeJSON() will maintain the case of your structure, but if you don't have control of the structure itself you need to do something to to convert only the structure keys to lowercase.

As a quick and dirty way of doing this I build a recursive function to do just that. Firstly I ran the structure through SerializeJSON() just in case the structure contained other datatypes that also need to be serialized, I think deserialized the string back into a structure. Make sure you use strict mapping so that the function doesn't try to convert your query back into a query. Then call the recursive function to go through and change all the keys to lowercase.

Here is the function:


    <cffunction name="convertStructToLower" access="public" returntype="struct">
        <cfargument name="st" required="true" type="struct">

        <cfset var aKeys = structKeyArray(st)>
        <cfset var stN = structNew()>
        <cfset var i= 0>
        <cfset var ai= 0>
        <cfloop array="#aKeys#" index="i">
            <cfif isStruct(st[i])>
                <cfset stN['#lCase(i)#'] = convertStructToLower(st[i])>
            <cfelseif isArray(st[i])>
                <cfloop from=1 to="#arraylen(st[i])#" index="ai">
                    <cfif isStruct(st[i][ai])>
                        <cfset st[i][ai] = convertStructToLower(st[i][ai])>
                    <cfelse>
                        <cfset st[i][ai] = st[i][ai]>
                    </cfif>
                </cfloop>
                <cfset stN['#lcase(i)#'] = st[i]>
            <cfelse>
                <cfset stN['#lcase(i)#'] = st[i]>
            </cfif>
        </cfloop>
        <cfreturn stn>
    </cffunction>

As you can see it also handles the case where you have an array of structures inside a structure.

I've tested it with nested structures that contain arrays of structures and it seems to work just fine. Perhaps you will find it useful for any Ajax stuff you are doing.

Happy Coding...

Coldfusion 9 Sharepoint Integration - getListItems

In my previous on the CFSharepoint tag and SharePoint Views we retrieved the meta-data columns for the specified view.

Now that we have the columns of the view we can build a CAML query to restrict what is returned when we get all the items of the list.

[More]

Ask Gary: Spry Tabs

I got an email recently asking me about the little tutorial I wrote some time ago on Spry Tabs with Dynamic Content.

I have been trying to improve my website but the problem I have with Spry Tabs and Dynamic Content is that I don't want the tab to reload every time a user goes back to a previous tab but at the same time when the page loads for the first time I want to take advantage of the click on demand option by only loading the defaults tab. Can you think of a solution. My users scroll between tabs and don't want to lose the search results displayed in each tab.

[More]

Coldfusion 9 Sharepoint Integration - GetView

In my last post on the CFSharepoint tag and Sharepoint ViewCollections we retrieved a list of the views associated to the specified list.

Allowing the user to select a list provides us the ability to restrict, to some degree, the meta-data that will be returned for a list item. There is a lot of meta-data available and while restricting the meta-data to just the view fields may actually be a little too restrictive. One column baseName contains the filename, if this is not a column in the view fields you will end up without an easily "digestible" file name. Specifically you will need to parse the file name out from the ows_FileRef column. The FileRef column contains a relative path to the file including filename with extension.

[More]

Coldfusion 9 Sharepoint Integration - ViewCollection

In my last post on the CFSharepoint tag and ListCollections we connected to a Microsoft Sharepoint server and using the ListCollection action of the CFSharepoint tag we retrieved a collection of all the lists available to the user.

In Sharepoint each list can have multiple views associated with it that show different meta-data for the list items. If you plan on integrating Sharepoint it is a good idea to provide the user the ability to choose the meta-data they want to view. In order to do this you need to allow them to choose the view.

[More]

Coldfusion 9 Sharepoint Integration - ListCollection

ColdFusion 9 saw the release of quite a bit of new functionality none so little blogged about as the new cfsharepoint tag. Not all surprising really since in order to use the cfsharepoint tag you need to have a Microsoft Sharepoint server at your disposal. Another reason it's probably not so often blogged about is that Sharepoint integration is going to be typically going on behind the scenes, integration projects with corporate Intranets and perhaps not really all that interesting for the masses.

Never the less I have decided to start a small series of blog posts on some of the different things you can do with the cfsharepoint tag. I will only be concentrating on document lists as that is where, in my opinion, most of the integration is going to be centered around.

[More]

Multiple Tomcat Instances as a Service

Yesterday I posted how to set up Multiple instances of Tomcat running Railo. The whole setup turned out to be relatively painless.

Running the multiple instances as a service is a small improvement that can make life a little easier. A small adjustment to the service.bat file is all that is needed in the Windows environment, a startup script for the linux environment could also be made/modified in a similar way.

[More]

Creating a Multi-Instance Railo Install with Tomcat

If you want to run multiple instance of Railo on a single server then keep reading because I am going to show you how to do just that using a single physical Tomcat and Railo install.

Requirements

You will need to have the latest Java JDK installed, then grab Tomat 6 zip, and Railo 3.1.2 Jars.

Once you have downloaded the required files we can begin.

[More]

Creating JPG Images with Rounded Corners

Rounded corners seem to be the next "big" thing for web designers, every damn box or image has to have a rounded corner. The problem is of course if you are using a content management system you can't possibly expect the users to first add rounded corners to the image before uploading it.

Thankfully there are a few different solutions, you could buy Image Effects, you could use ImageDrawRoundRect() function as shown by Gareth, or use a Java solution as shown on cfSearching.

If you want to do more than just rounded corners with your images it may well be worth forking out the $50 bucks for the Image Effects component from Foundeo.

CF8 ImageDrawRoundRect()

I tested the method by Gareth and found that the quality of the image even after setting the image quality to 100% produced image aberrations in the corners of the produced jpg image.

Java, but PNG Only

I also tested the Java method by leigh at cfSearching and was impressed with the quality of the image, the only problem was that it only worked with png images and I needed it to work with JPG.

Java, JPG Rounded Corners

[More]

Using ProxyPassMatch

Building on from the Clustering Railo with Tomcat and Apache article we set up the Railo Tomcat cluster but it was set up to send all requests on to Tomcat. While in a low traffic site sending every single request to Tomcat for processing may not be a big deal, you probably haven't gone through the trouble of setting up a cluster for a low traffic environment therefore, you certainly want to squeeze as much performance out of your available resources.

[More]

Clustering Railo with Tomcat and Apache

This post is a result of a request from a client of ours to have a Railo cluster. The original idea was to use jBoss but ended up settling on stand-alone Tomcat instead.

We are going to set up a "High-Availability" cluster with load balancing using Apache to perform the proxying, Tomcat as our servlet container and Railo to serve up our CFML. You notice that I placed high availability in quotation marks; this is because while automatic failover will be enabled our sessions won't be replicated to all nodes in the cluster. The reason we won't be replicating the sessions is mainly because of performance reasons.

[More]

Ask Gary: Appending URL Variable to rsslink

Got a question in my email box from Chris asking the following:

Hi Gary, First, thank you for creating the RSS Feed tutorial. It was very helpful. Second, sorry to bother you, but I need to append a URL variable to the link. I could do this when inserting an article into the database (i.e. '#Request.url#?article=#Variables.uuid#') but as I need to insert the UUID anyway, it's just plain clunky. Do you know if there is a method or better way to do this?

[More]

A Insanley Simple jQuery Accordion

We have a couple of projects currently running in parallel and as always resources are a bit in short supply. This has given me the opportunity to put on my developer hat a bit and help out a bit. This time with building a simple jQuery accordion. I didn't want to use the accordion widget so I quickly put together a quick little example for the developer to integrate into the project.

[More]

Installing Railo 3 on SUSE 10 with Apache2 and Tomcat: Part 2

In my previous post we set up our SUSE 10 VM, Installed Apache and Tomcat and got Tomcat to start up without throwing any error messages. In this post we will continue with the installation of Railo and then hook Tomcat up to Apache, and finally make an index.cfm page and check that everything is working.

[More]

Installing Railo 3 on SUSE 10 with Apache2 and Tomcat: Part 1

Earlier this week I mentioned that I had successfully installed Railo on a SUSE 10 Enterprise virtual machine. I had also said that I would provide a step-by-step guide on how you can achieve the same. Hopefully this guide will help you set up your instance a heck of a lot faster than it took me to set up mine.

[More]

SEO & Ajax

How do you provide your customers with the Ajax functionality they want and still optimize the site for search engines?

[More]

Tracking Digital Content

One of our clients an electronic entertainment company provides movie trailers on their site. They also want to provide their partners with a simple EMBED tag for a flash player similar to what youtube does with it videos. Naturally they want to be able to track how often the movie clip or trailer is viewed on their partners sites by using google analytics, or as yet to be determined tracking methods.

[More]

Capitalize Names Updated

Just a quick note about my Capitalizing Peoples Names post yesterday. I forgot to change the extension of the enclosure to something other than .cfm.

I updated the enclosure and also further optimized my function. You should now be able to download the function.

Happy Coding...

Capitalizing Peoples Names

While doing a code review at work I stumbled accross a horrible piece of code that was written in a hurry, The developer did the best he could at the time with the time that he had available to him to complete the task. He never really had time to think it though so just continued to throw worse code after bad until the problem was eventually solved.

The Problem

There has to be a better way to do what he was doing and so when I got home from work today I decided to actually look at the problem in the context of the system we have.

[More]

Spry Dynamic Tabs 2

A reader recently asked about my Spry Panel with Dynamic Content post:

How do I extend it to automatically generate each TAB from an external file as well.

The tabs are generated from [an] external XML data (the XML contains the link to be run when the Tab is clicked), and then each tab generates it's content when it is clicked.

In my post the tabs were hard coded, to dynamically generate the tabs using an xml file and then dynamically load the content specified in the xml file it's just a little bit more work (but less typing!).

[More]

What Function Called My Function

I read a post on the Adobe forums by Spike H asking:

I have written a utility component (test1 below) and want to keep track of what external functions call the functions within my component. Other programmers create a component (e.g. test2 below) that extends my utility component and then their functions call my functions. I want to record metric data to determine how much use my functions are getting and from where. I've used the getMetaData() function inside my functions, but that only gives me the name of the component that extends my component (in this case test2), not the specific function that called my function (in this case functionAtest2).

[More]

Inline Rich Text Editor

I've been looking for a example of using a HTMl rich text editor in a customer site to provide the ability for wysiwyg style editing of content items.

Basically the page would be displayed as a user would see it, they would then click (or double click) on the content item in question which would then be replaced with either a text box or rich text editor where appropriate. Much like flickr does with the image title and description but also with the rich text capabilities. A lot of commercial content management systems provide this type of functionality already but I haven't been able to find an example that I could easily rip off duplicate.

[More]

CFGRID Cell Renderer Revisited

As I mentioned in my post on Monday via a post on Ray Camden's site creating customized cell renderers are possible, though not officially supported in CFGRID.

What that actually means is that CF doesn't provide a simple way of specifying a cell render for a grid column as shown in the hypothetical code snipet below:

[More]

Coldfusion 8 SFTP with CFFTP

Another great addition in Coldfusion 8 is support for SFTP. Prior to CF8 you were pretty much restricted to regular FTP.

We have had occasions where we needed to perform SFTP access to an offsite server and the security requirement for the server was SFTP only (completely acceptable). We wanted to set up a scheduled event to go and collect some xml files from the customers server for further processing all via SFTP.

[More]

CFIMAGE Part 4: Remote Images

The Coldfusion 8 CFIMAGE tag allows you to work with remote images simply by providing a URL to the desired Image, this makes grabbing images from places such a flickr (which I use as an online backup of most of my images) easily.


<cfimage source="http://farm1.static.flickr.com/97/232021390_ad47422845_o.jpg" name="MyImage"/>
<cfimage source="#MyImage#" action="writeToBrowser"/>

This works just fine, even for really large images of 1368x2048. You can also manipulate your remote image in various ways there is one thing, however, you should be aware of when working with remote images.

Small Gotcha

I managed create a runtime error when trying to read the EXIF or IPTC meta data from the remote image.

Exception occured in JPG processing. segment size would extend beyond file stream length

This only occurred on big images, I tried with a fewer smaller images and CF had not problems.

Happy Coding...

CFIMAGE Part 2

In my previous post CFIMAGE Part 1 we created a simple image and added some text to the image and wrote it out directly to the browser.

In this post we will look at the EXIF data of an image. Typically the EXIF or Exchangeable Image File Format gets written to an image mostly during the creation process of modern digital cameras and only with JPEG images. Some additional information may get written to the image during post processing in Photoshop or other imaging software.

[More]

CFIMAGE Part 1

I was looking through the Coldfusion docs today, specifically at the cfimage tags and all the goodness that they bring to CF. I'm continually amazed at the level of integration that CF8 has with other Adobe products, specifically in the area of PDF's and Images.

[More]

Ext Tree adding a Context Menu

In the previous Ext Tree and Coldfusion Example post we set up an EXT treeview bound to a Coldfusion component.

In this example we will be building upon that example to add a dynamic context menu to our tree. The context menu will be populated by calling a function in a Coldfusion component.

Step 1

The first thing we need to do is include the below snippet of code in the head section of our page, but after the ext-all.js.

[More]

Ext Tree and Coldfusion Example

The EXT tree is, in my opinion, a much better implementation of a dynamic ajax tree than what the yahoo utility toolkit starts out with, and subsequently what Adobe decided to use for the CFTREE tag. Once again I am really amazed at the quality work that Jack and his crew have done. The tree itself is relatively simple to set up as either a static tree or dynamic tree. In the example code I will be showing I have set up the tree to have a lazy loader. This means that I will only be showing the root (and in this case the first set of children) of the tree and each time a node is clicked a call will be made to populate that nodes children.

[More]

Coldfusion 8 Binding a Grid to a Tree

In a previous post I mentioned that I probably wouldn't be using these two tags because they just don't provide me with the flexibility that will allow me to give our customers what they will likely want. But that doesn't completely remove their usefulness, it just reduces it to very specific applications. It still is a good way to demonstrate binding different UI elements together.

As the title states we are going to be binding a tree's select event to a grid. This means that when a user clicks on a node of a tree an Ajax call will be made to repopulate the grid.

Lets pretend for a moment that we have a cfTree named "myTree" in a form called "myTreeForm" and our tree is populated via its own bind call to a cfc that returns directories.


    <cfform name="myTreeForm" >
        <cftree name="myTree" height="400" width="200" format="html">
            <cftreeitem bind="cfc:#request.cfcpath#.fileExplorer.getDirectories({cftreeitempath},{cftreeitemvalue})">
        </cftree>
    </cfform>

Now lets further pretend that we also have a grid called fileGrid in a form called gridform. This grid could be on the same page, or not, but is also subsequently bound to a method in a component that returns files in a specified directory.

[More]

EXT Ajax Grid Part 2

This is the second installment of building an Ajax grid using the EXT UI and Coldfusion.

In Part 1 we included the library files and set up the Javascript and HTML to render our Grid with paging.

In this entry we will set up an Ajax wrapper component and a component to populate our grid.

We need an Ajax wrapper component in this example because we are not using Coldfusion 8, the Ajax component will act as an intermediary component to instantiate our component and output the results. We could also use a standard cfm page but I prefer to use a component.

ajaxwrapper.cfc


<cffunction name="getFiles" access="remote" output="yes">
    <cfargument name="start" default="1" required="yes"/>
    <cfargument name="limit" default="10" required="yes"/>
    <cfargument name="sort" default="" required="yes"/>
    <cfargument name="dir" default="" required="yes"/>
    <cfargument name="callback" default="" required="no"/>
<!--- the ext grid sends a 0 for the start by default, the startrow attribute on the cfoutput tag must be greater than 0 so we take care of that here before calling the component.--->        
        <cfif start eq 0>
            <cfset start = 1>
        </cfif>
        <cfset obj = createobject("component","fileExplorer")/>
        <cfset retval = obj.getFilesExt(start,limit,sort,dir,"/dev/crucial")/>
        <cfoutput>#callback##retval#</cfoutput>
        
</cffunction>

[More]

Coldfusion 8 CFIMAGE and CAPTCHA

A lot of people have created a variety of different CAPTCHA implementations to help combat spam and bots from flooding comment sections on blogs or automated signup's to name only a couple.

BlogCFC uses the lyla captcha written by Peter Farrell. There are also quite a few third party tools you can also buy. Or with Coldfusion 8 you can simply use the CFIMAGE tag to create one yourself.

The reference manual says that you must provide a width attribute that is at a minimum the (fontsize * number of chars * 1.08)

Here is an example of creating a CAPTCHA image with the new CFIMAGE tag.


<!--- font size = 25, number of characters = 8, then magic number 1.08 --->
<cfset size = 25 * 8 * 1.08/>
<cfimage action="captcha" fontSize="25" width="#size#" height="50"
text="IAmHuMan" fonts="Verdana,Arial,Courier New,Courier" difficulty="low">

This creates the following image:

Bumping up the difficulty to medium produces an image with a bit more distortion.

And pushing the difficulty all the way up to "high" you end up with something like this:


The method I employed in the example code above writes the image directly to the browser.

If you decide to generate the text for your captcha image randomly there is no way for you to determine what is written to the image unless you save your random text into a variable that will be available to you after the form is submitted. For obvious reasons you shouldn't stick it into a hidden form variable.

I would suggest putting it into a session variable when you display the captcha image and then you can compare what you have in your session variable to what the user typed into the form field.

EXT Ajax Grid Part 1

I recently posted an example on using one of the Coldfusion 8 Ajax CFGRID. I also mentioned at the time that it's based upon the GUI Library found at ExtJS.com. Well I thought it would be a good idea to also show an example on how to set up a grid using the library.

In Part one I will introduce you to the front end part, that is the javascript code to set up the grid, as well as what files you need to include in order to get it working. The next part we will go through the Javascript. And then in the final part I will show you how I set up the return data. Since I do not have Coldfusion 8 on my hosting provider we will build then entire thing using Coldfusion 6 or MX tags and functions.

So lets get started....

There are some necessary files you need to include at the top of the page that you want to have the grid on. The files are the base Yahoo utilities file, an yahoo to ext adapter and then the main ext library. Jack recently moved away from dependence on a third party base library and has created his own so in the future we won't need to have the yui-utilities included but the ext base library instead.

If you don't have the base library yet you can get it from the Extjs download area.

Put the code below into the html head of your page making sure to change the paths to where you have your resources.


<!-- these two library's must be included before any others -->
<script type="text/javascript" src="resources/javascript/yui-utilities.js"></script>
<script type="text/javascript" src="resources/javascript/ext-yui-adapter.js"></script>
<!-- the main ext library -->
<script type="text/javascript" src="resources/javascript/ext-all.js"></script>
<!-- this is the main styleshee, it is also broken down into separate stylesheets for each 'widget' -->
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css"/>

The next thing we will do is set up our grid. In the head area of your HTML document drop in the following:

[More]

CFLayout

Two new tags introduced by Coldfusion 8 are the <cflayout> and <cflayoutarea>, which is cflayouts child tag.

As the name suggests these two tags deal with laying out a page, duh! What is interesting about these two tags as with the CFTREE and CFGRID mentioned in earlier posts, is that they remove some of the complexity of creating these user interface pieces. And again CF8 is using the EXTjs UI framework here as well.

You have four layout style options when using the cflayout area tag, those being: border, hbox, vbox and tab. The hbox and vbox options are relatively understood (they layout the child tags either horizontally or vertically) the Border and Tab layout options are a bit more interesting.

[More]

Coldfusion 8's CFTREE tag

Coldfusion 8 introduced support for an HTML tree. With the HTML tree you can build an AJAX driven tree, which means you only need to load the to level nodes at first and all subsequent child nodes and leaves are only loaded when needed. The old requirements of the cftree tag, that being living inside of a cfform still exists.

You set up your tree like so:


<cfoutput>
    <cfform name="myform">
        <cftree name="treeTest" height="400" width="200" format="html">
            <cftreeitem bind="cfc:components.tree.getNodes({cftreeitempath},{cftreeitemvalue})">
        </cftree>
    </cfform>
</cfoutput>

The bind expression, like in my previous post about the cfgrid, is used to bind the creation of the tree elements to the output of a CFC.

[More]

Coldfusion 8's CFGRID

One of the tags to receive an upgrade in CF8 is the CFGRID tag. I can honestly say that I have never had a need to use this tag in the past although for some I can see that it 'could' have been useful.

The added support comes in the form of: type="html",bind,bindOnLoad,pageSize,prefesrbPageOnSort,stripeRows,stripeRowColor.

Lets focus for a minute on the new bind attribute. This attribute allows you to specify an expression to fill the grids contents. This expression can come in three flavors: You can bind directly to a CFC, a javascript function, or additionaly a URL.

The old restriction on the cfgrid is still in place, that being that it has to live within the bounds of a CFFORM tag, that's a small price to pay for ajax functionality right?

So here is a code snippet of the cfgrid in action:

[More]


Powered By Railo

Subscribe

Subscribe via RSS
Follow garyrgilbert on Twitter Follow me on Twitter
Or, Receive daily updates via email.

Tags

adobe air ajax apple cf community cfml coldfusion examples ext flash flex google javascript jquery max2007 max2008 misc open source programming railo software technology ui

Recent Entries

No recent entries.

Blogroll

An Architect's View
CFSilence
Rey Bango
TalkingTree

Wish List

My Amazon.com Wish List