Cold Fusion

April 16, 2008

My Struct() Custom Data Type that Binds

I’ve wanted to have a struct (hashtable) class that I can use for some time that also bind to controls like List, DataGrid, etc… Dictionary works fine, it just didn’t update the bindings. I just hadn’t figured out how to make sure how to make sure it’s dispatching events.  But I finally got around to creating a class that behaves more like a cold fusion struct that I can bind to. You can’t bind to it using brackets, but you can read values by key and set values by key. To bind by key there’s a method you have to go through.  You can get the class here

Struct.as (1 KB)

Here’s a brief run down of use cases:

Create a new Struct

[Bindable]

public var struct : Struct = new Struct();

Set a value 

struct[key] = value or struct.addByKey(key,value);

Read a value

struct[key] or struct.getByKey(key);

Bind to a value by key

{ struct.getByKey(key) }

September 17, 2007

Using Cold Fusion onRequest and flex remoting

If you want to use the Application.cfc onRequest method for processing .cfm pages and at the same time want to have sub directories for .cfc’s that serve as web services or methods for flex remoting it is possible.

I know there are a bunch of posts that show how to do this and so I thought I’d point out that my work around takes the reverse approach than what I’ve seen on other blogs. It basically adds those methods into the variables scope to be called if it doesn’t find a .cfc in the page name. You could obviously look for whatever you needed in that <cfif> statement, and I actually use it to look up the word “api” in the CGI.HOST_NAME variable which is where I route my flex remoting calls.

 

 <cfif not findNoCase("cfc",SCRIPT_NAME)>
   <cfset variables["onRequestStart"] = variables["onRequestStartHandler"] />
   <cfset variables["onRequest"] = variables["onRequestHandler"] />
   <cfset variables["onRequestEnd"] = variables["onRequestEndHandler"] />
 </cfif>

 <cffunction name="onRequestStartHandler" access="public" returntype="boolean">
 
  <cfreturn true>
 </cffunction>
 
 
 <cffunction name="onRequestHandler" access="public" returntype="boolean">
 
  <cfreturn true>
 </cffunction>
 
 
 <cffunction name="onRequestEndHandler" access="public" returntype="boolean">

  <cfreturn true>
 </cffunction>

Tags: