Why do people forget about JSStringFormat?

coldfusion , JavaScript 102 Comments »

I thought it was worth a quick post before I call it a night. Lately as I converse with colleagues who are getting more and more into the whole "Web 2.0" thing and therefore using more AJAX and JSON, I notice I'm sometimes the only one in the circle who recalls the awesome ColdFusion function JSStringFormat.

With this function you can take any amount of content and make it JavaScript friendly - you know, escaping single quotes and all that jazz. Even better is when you couple it with the cfsavecontent tag. Check this out, it's how I make a no-flash display.

<cfsavecontent variable="foo">This is some markup, can contain tons and tons of tags, even other script, etc.</cfsavecontent>
<cfoutput>
<script language="text/javascript">
var foo = '#JSStringFormat(foo)#';
</script>
</cfoutput>

Testing Image Insert (Picasa)

74 Comments »

Let's see if I can easily get a medium sized image in here via Google Picasa's standard embed code.

Ireland Rules!

ColdExt, the ExtJS Gateway Drug

coldfusion , extjs , JavaScript , Framework , AJAX , cftags 94 Comments »

Quick post tonight, as I'm between tasks. I've been wanting for a long time to get more familiar with ExtJS, a most excellent JavaScript application framework (can I call it that?). It's the good stuff that's built into ColdFusion 8, but that was version 1.1. Since then they've gone all the way to 3.0, and the platform is getting better and even more expansive.

What I wanted to do was get into it, but I kept getting sidetracked. It can be a bit to digest in one sitting - or even 10. Eventually, I heard of ColdExt, which is a ColdFusion, er, helper application... well, it's like training wheels. I hope that doesn't offend anyone - particular the ColdExt gang. It's really amazing what they've done. Using their imported tags you can get off the ground really fast using the familiar tag-ness that is ColdFusion but when it's processed and sent to the browser it's all proper ExtJS JavaScript.

Now, I LOVE this. What it's doing is providing me, the developer, those all-important positive and productive feedbacks we call "success". In no time I had an AJAX-powered grid with a CRUD form hooked up to the rows. Even better is that some of the things I wasn't completely familiar with in the ExtJS syntax was getting written for me. A quick view-source and I was staring at a guide for how the under-hood-goods were written. This has helped me gain mountains of comfortability with this JavaScript framework!

So, even if you don't want to use ExtJS through a layer of ColdFusion tags in the end, I highly recommend you ease into the deep and incredibly powerful world of ExtJS via ColdExt. It put the "RAD" back into my AJAX/Rich Client applications. That's just awesome.

Fusebox: a legacy

community , Framework , fusebox 79 Comments »

After keeping up with Adam Haskell's frustrations with Fusebox (well, with the vested interests, to be fair) it got me thinking about what Fusebox means to me. I mean, sure, I've thought about ColdBox and ModelGlue and even on a particularly spunky day Mach-II. But each morning I wake up and I'm still a Fusebox developer after 9 or so years.

So with project Fusebox being somewhat of a rudderless ship, or coffee-less donut, or Guinness-less me (you get the picture) where does that leave the Fusebox community? As rich as it ever was, I say!

It's a great framework because it started out dead simple. I started on FB2 and then wrote most of my professional code in FB3. Man, those were the days! Pop some variables into the ole' fbx_Settings file and away you go! It was a snap to get new hires up and running. Then FB4 came, and with it came XML - some kind of new, alien acronym that looked all foreign-like. ;) We pretty much ignored that version. Then along came FB5 and I had to figure out what all the hub-bub was about, so I immersed myself in that. Now I'm a FB5 fan through and through. Yep, you heard me right - a fan of the leader-less, roadmap-less framework.

It's left behind a great legacy with the community. So many applications (many still running) and so many wise lessons learned the hard way. It taught us why a framework is good, it inspired us to try to better it (nod to the sibling frameworks) and it gave some much-needed shape to the wonderfully flexible language that Allaire- er, Macromedia- er, Adobe had given to us.

Personally, I'm going to revel in my continued embrace of Fusebox. Having a fleet of major applications deployed using that technology might have something to do with that, but it's also a feeling of trust and familiarity. Let's not forget, too. We do have FuseNG! Let's wish the Fusebox/FuseNG community further longevity, whether it be called tomayto or tomahto. Just don't call the whole thing off.

Follow up: JSON value object from Transfer via ColdSpring remote proxy

transfer , ORM , AOP , AJAX , coldspring 115 Comments »

I think I found myself a solution. First, here's the problem.

The Problem

I have Transfer managing my ORM. It works awesome, I love it, and now I want to start building AJAX-based tools to manage the data through Transfer. But Transfer hides all properties of a class behind getter and setter methods, so when I hit a remote CFC to get, say, new("person") or get("person", 42), all that comes back in a JSON string is {}. No properties visible, so nothing comes back.

The Solution

My LTOFactory (Lightweight Transfer Object) is a component that will talk to Transfer, get the object I'm looking for, and then return the product of Transfer-ORM's built in getMemento() method, which is a simple struct that contains all the properties - publicly exposed. Now my JSON string has the properties!

The same concept for the get method can be, with a little elbow grease, made to work also for list, save, and delete if I choose. If I do that, LTOFactory probably isn't a very good name anymore, but I'm talking results here, not semantics.

The Code

Here is my LTOFactory code.



<cfcomponent output="false">



   <cffunction name="init" returntype="Any" output="false">
      <cfargument name="transfer" type="Any" required="true" />
      <cfset variables.instance["oTransfer"] = arguments.transfer />
      <cfreturn this />
   </cffunction>


   <cffunction name="new" output="false">
      <cfargument name="class" type="string" required="true" />
      <cfscript>
         // Feign a local private scope (coming soon in CF9!)
         var local = {};
         // Retrieve the new Transfer Object (TO) from the Transfer factory
         local.o = variables.instance["oTransfer"].new(arguments.class);
         // Return the memento for the new object
         return local.o.getMemento();
      </cfscript>
   </cffunction>


   <cffunction name="get" output="false"><!--- not yet implemented ---></cffunction>


   <cffunction name="list" output="false"><!--- not yet implemented ---></cffunction>



</cfcomponent>


Here is my ColdSpring configuration that sets up Transfer, its factory, the LTOFactory with dependency injection, and the AOP remote bean configuration so I can hit the LTOFactory via AJAX.

<?xml version="1.0" encoding="iso-8859-1"?>
<beans>
   <!-- Transfer -->
    <bean id="transferFactory" class="transfer.TransferFactory">
      <constructor-arg name="datasourcePath"><value>datasource.xml</value></constructor-arg>
      <constructor-arg name="configPath"><value>transfer.xml</value></constructor-arg>
      <constructor-arg name="definitionPath"><value>/definitions</value></constructor-arg>
      <singleton>TRUE</singleton>
    </bean>

   <bean id="transfer" factory-bean="transferFactory" factory-method="getTransfer" />

   <bean id="LTOFactory" class="LTOFactory">
      <constructor-arg name="transfer">
         <ref bean="transfer" />
      </constructor-arg>
   </bean>

   <bean id="remote.LTOFactory" class="coldspring.aop.framework.RemoteFactoryBean">
      <property name="target">
         <ref bean="LTOFactory" />
      </property>
      <property name="serviceName">
         <value>RemoteLTOFactory</value>
      </property>
      <property name="relativePath">
         <value>/remote/</value>
      </property>
      <property name="remoteMethodNames">
         <value>get,list,new</value>
      </property>
      <property name="beanFactoryName">
         <value>bf</value>
      </property>
   </bean>
</beans>
Powered by Mango Blog. Design and Icons by N.Design Studio
RSS Feeds