Viewing by month: October 2005

Oct 31 2005

Arf! Rails-Like ActiveRecord for ColdFusion

I'd like to introduce "Arf!" (Active Record Factory!), a Rails-style ActiveRecord implementation in ColdFusion. I have to disclaim this by saying that I have mixed feelings about ActiveRecord - it's at the same time very nice for doing things quickly, but I think it's ripe for abuse, as it's easy to think it's the begin and end all of OO programming. However, I think it's also a great way to stop writing some of the same blasted code over and over again for simple projects.

Read more...

24 comments - Posted by Joe Rinehart at 10:06 PM - Categories: ColdFusion MX | Model-Glue | Arf!

Oct 27 2005

Super Abuse and "Method Injection"

Ok, so I've railed a bit in private against CFC "method injection." I don't think it's a good habit to be into - I'm all about programming to interfaces, not writing programs that define interfaces as they go along.

However, I *am* in a situation dealing with a low-level framework (not Model-Glue) issue where I need to modify the functions inside of a CFC's _base_ (don't ask why, I'll release what I'm up to before too long). What follows is a hack that's probably of limited use, but interesting nonetheless.

If you CFDump the Super scope within a CFC, you'll get an object. It's got a few interesting things, like Get() and Put() methods. These seem to act on the public scope of the CFC that's the base.

By using the Put() method, we can then add things to the base method.

Demo:

<!--- Base1.cfc --->
<cfcomponent>
   <cffunction name="test">
      <cfreturn "Base 1 version!!" />
   </cffunction>
</cfcomponent>

<!--- Base2.cfc --->
<cfcomponent>
   <cffunction name="test">
      <cfreturn "Base 2 version!!" />
   </cffunction>
</cfcomponent>

<!--- Concrete.cfc --->
<cfcomponent extends="base1">
   <!--- Show the initial definition of super.test() --->
   <cfoutput>#super.test()#</cfoutput>

   <!--- Change the definition of super.test() --->
   <cfset otherBase = createObject("component", "base2") />
   <cfset super.put("test", otherBase.test) />
   
   <!--- Show the final definition of super.test() --->
   <cfoutput>#super.test()#</cfoutput>
</cfcomponent>

Displays:

Base 1 version!!
Base 2 version!!

Crazy stuff.

1 comments - Posted by Joe Rinehart at 9:50 AM - Categories: ColdFusion MX

Oct 21 2005

FrozenFlex: Using CFQuery in Flex

Want to display a CF query's results in Flex? Here's how, with a minimum of fuss! In this FrozenFlex edition, we'll introduce the WebService tag, a data model, and how we can use them to interact with ColdFusion server via Web Services.

Read more...

6 comments - Posted by Joe Rinehart at 3:25 PM - Categories: Flex and ColdFusion

Oct 20 2005

FrozenFlex: CFQuery in Flex Preview

In last night's FrozenFlex post, we looked at how to create a detail form. In the next post, we'll look at the mechanics of delivering a CFQuery to a Flex datagrid, but for now, here's a preview:

http://clearsoftware.net/flex/cfquery.html

Note that you'll need the Flex 8.5 player installed - it's available at http://labs.macromedia.com as part of the Flex Builder 2 public alpha.

For those of you who want a headstart, here's the code that I'll be explaining when I take a break from work tomorrow:

<!--- QueryDemo.cfc --->
<cfcomponent>

<!--- Build a big dummy query --->
<cfset contacts = queryNew("Firstname,Lastname") />
<cfset queryAddRow(contacts, 5) />

<cfset querySetCell(contacts, "Firstname", "Joe", 1) >
<cfset querySetCell(contacts, "Lastname", "Rinehart", 1) >

<cfset querySetCell(contacts, "Firstname", "Doug", 2) >
<cfset querySetCell(contacts, "Lastname", "Hughes", 2) >

<cfset querySetCell(contacts, "Firstname", "Sean", 3) >
<cfset querySetCell(contacts, "Lastname", "Corfield", 3) >

<cfset querySetCell(contacts, "Firstname", "Jared", 4) >
<cfset querySetCell(contacts, "Lastname", "Rypka-Hauer", 4) >

<cfset querySetCell(contacts, "Firstname", "Dave", 5) >
<cfset querySetCell(contacts, "Lastname", "Carabetta", 5) >

<!--- Provide a web service on the dummy query --->
<cffunction name="search" returntype="query" access="remote" output="false">
<cfargument name="searchCriteria" type="string" required="true" />

<cfset var result = "" />

<cfif len(arguments.searchCriteria)>
<cfquery dbtype="query" name="result">
SELECT
*
FROM
contacts
WHERE
UPPER(firstname) LIKE '%#ucase(arguments.searchCriteria)#%'
OR UPPER(lastname) LIKE '%#ucase(arguments.searchCriteria)#%'
</cfquery>
<cfelse>
<cfset result = contacts />
</cfif>

<cfreturn result />
</cffunction>
</cfcomponent>

And CFQuery.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*" backgroundColor="#FFFFFF" creationComplete="search()">
   
   <!-- Service -->
   <mx:WebService
   id="ContactService"
   wsdl="http://clearsoftware.net/net/clearsoftware/QueryDemo.cfc?WSDL"
   useProxy="false" showBusyCursor="true">

<mx:operation name="search">
<mx:request>
<searchCriteria>{searchCriteria.filter}</searchCriteria>
</mx:request>
</mx:operation>
   </mx:WebService>

   <mx:Model id="searchCriteria">
      <filter></filter>
   </mx:Model>
   
   <mx:Script>
      <![CDATA[
         function search() {
            searchCriteria.filter = searchString.text;
            ContactService.search.send();   
         }
      ]]>
   </mx:Script>
   
<mx:ArrayCollection id="ac"
source="{mx.utils.ArrayUtil.toArray(ContactService.search.result)}"/>

   <mx:Panel height="100%" width="100%" backgroundColor="#CCCCCC" cornerRadius="5" title="Model-Glue Code Contributors">
      <mx:Canvas height="100%" width="100%">
         <mx:TextInput id="searchString" y="9">
            <mx:layoutConstraints>
               <mx:EdgeAnchor right="58" left="75"/>
            </mx:layoutConstraints>
         </mx:TextInput>
         
         <mx:Label x="5" y="12" text="Filter:"/>
         <mx:Button label="Ok" id="searchButton" click="search()" y="9">
            <mx:layoutConstraints>
               <mx:EdgeAnchor right="5"/>
            </mx:layoutConstraints>
         </mx:Button>
         <mx:DataGrid dataProvider="{ac}">
          <mx:layoutConstraints>
          <mx:EdgeAnchor right="5" left="5" bottom="5" top="37"/>
          </mx:layoutConstraints>
          <mx:columns>
          <mx:DataGridColumn columnName="Firstname" headerText="First Name"/>
          <mx:DataGridColumn columnName="Lastname" headerText="Last Name"/>
          </mx:columns>
         </mx:DataGrid>
      </mx:Canvas>
   </mx:Panel>
</mx:Application>

15 comments - Posted by Joe Rinehart at 8:41 PM - Categories: Flex and ColdFusion

Oct 20 2005

Flex 2 Listserv

Raymond Camden (host of the CFCDev list) has set up a listserv just for Flex 2 development. I'm hoping it'll get a good mix of the Flex and ColdFusion community - subscribe now by sending a message of 'subscribe' to flex2dev@cfczone.org.

2 comments - Posted by Joe Rinehart at 12:15 PM - Categories: Flex and ColdFusion

Oct 20 2005

FrozenFlex: A Basic Form

Welcome to FrozenFlex! This is a series of blog posts I'll be making to both share and reinforce my own learning process in Flex 2 backed by ColdFusion. I'm going to be building a contact manager (imagine that!) by learning some basic building blocks, putting the whole thing together, and then moving it towards the Cairngorm framework.

Read more...

5 comments - Posted by Joe Rinehart at 7:59 AM - Categories: Flex and ColdFusion

Oct 19 2005

Cairngorm for Model-Glue Developers

I'm going to be learning the Flex Cairngorm framework over the next few weeks. It's an implementation of Front Controller for Flex developed by iteration::two (now part of Macromedia, soon part of Adobe...).

There's a good deal of conceptual similarity between it and Model-Glue, so I'm thinking of writing a blog entry / article / maybe a preso on how to get up and running with it that's targeted towards Model-Glue developers, showing how terms from Model-Glue translate into Cairngorm, as well as introducing new terms (ViewLocator? ServiceLocator?).

Anyone have any interest in such a thing?

5 comments - Posted by Joe Rinehart at 8:59 AM - Categories: Model-Glue | Flex and ColdFusion