Quick RIAForge Update

I just spent five minutes on RIAForge changing the search page to use JSON instead of XML. I know I've said this before, but you got to love the size differences. Before the change, the size of the XML packet downloaded was 152KB. With JSON it's down to 72KB.

For those who may view source - please note that I didn't really touch much else - so the code could be even better probably (using the Paged Data support instead of my manual paging for example).

I've blogged about how I integrate Model-Glue with AJAX before, but here is a quick recap. When I make an event that is meant to serve data up to an Ajax client, I first broadcast my message to get my data:

<message name="GetApprovedProjects"> <argument name="mode" value="short" /> </message>

I then broadcast a generic message:

<message name="ToJSON"> <argument name="viewstatekey" value="projects" /> </message>

My controller code for ToJSON does:

<cffunction name="toJSON" access="public" returnType="void" output="true"> <cfargument name="event" type="any"> <cfset var viewKey = arguments.event.getArgument("viewstatekey")> <cfset var data = ""> <cfset var json = "">
&lt;cfif arguments.event.valueExists(viewkey)&gt;
	&lt;cfset data = arguments.event.getValue(viewkey)&gt;
	&lt;cfset json = serializeJSON(data,true)&gt;

&lt;cfset arguments.event.setValue("json", json)&gt;	


So in case that isn't obvious - what it means is I can broadcast any message and just pass the results to a generic JSON converter. (The view just dumps out the JSON string.)

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com