Spry Demo Updated

I updated my Spry demo, again, this time with a few fixes. First, the URL:


Just in case it isn’t obvious, this is an AJAX front end to this blog. The only thing different from the “real” blog is that I limit the total amount of entries per category to 100. So what changed? First, there was a bug in paging and sorting. If you sorted, it only applied to the current page, and not the entire set. This was fixed thanks to Adobe. The fix will be in the next release of Spry. (Lucky me, I know all the right people. :)

The second fix was more interesting. I noticed that the HTML data wasn’t being rendered right. My HTML was being escaped. Turns out this made sense as my CFC was xmlFormatting the result. Kin Blas of Adobe (one of the Spry folks) pointed out that I need to CDATA wrap my result. Let me show you how I did that in my CFC:

<cffunction name="queryToXML" returnType="string" access="private" output="false"> <cfargument name="data" type="query" required="true"> <cfargument name="rootelement" type="string" required="true"> <cfargument name="itemelement" type="string" required="true"> <cfargument name="cDataCols" type="string" required="false" default="">

&lt;cfset var s = "&lt;?xml version=""1.0"" encoding=""UTF-8""?&gt;"&gt;
&lt;cfset var col = ""&gt;
&lt;cfset var columns = arguments.data.columnlist&gt;
&lt;cfset var txt = ""&gt;

&lt;cfset s = s & "&lt;" & arguments.rootelement & "&gt;"&gt;
&lt;cfloop query="arguments.data"&gt;
	&lt;cfset s = s & "&lt;" & arguments.itemelement & "&gt;"&gt;

	&lt;cfloop index="col" list="#columns#"&gt;
		&lt;cfset txt = arguments.data[col][currentRow]&gt;
		&lt;cfif listFindNoCase(arguments.cDataCols, col)&gt;
			&lt;cfset txt = "&lt;![CDATA[" & txt & "]]" & "&gt;"&gt;
			&lt;cfset txt = xmlFormat(txt)&gt;
		&lt;cfset s = s & "&lt;" & col & "&gt;" & txt & "&lt;/" & col & "&gt;"&gt;

	&lt;cfset s = s & "&lt;/" & arguments.itemelement & "&gt;"&gt;

&lt;cfset s = s & "&lt;/" & arguments.rootelement & "&gt;"&gt;

&lt;cfreturn s&gt; &lt;/cffunction&gt; </code>

This method, queryToXML, translates a query to XML. (Duh.) There is a method for this already at CFLib, but I wrote mine from scratch because I like doing that. My fix today was to add a new optional argument, cDataCols. This lets me specify which query columns will contain HTML and should be CDATA wrapped instead of xmlFormatted. All I did then was to simply change my call in getEntries:

<cffunction name="getEntries" returnType="xml" access="remote" output="false"> <cfargument name="category" type="uuid" required="true"> <cfset var s = structNew()> <cfset var q = ""> <cfset s.maxEntries = 100> <cfset s.byCat = arguments.category>

&lt;cfset q = variables.blog.getEntries(s)&gt;

&lt;cfcontent type="text/xml"&gt;	
&lt;cfreturn queryToXML(q, "entries","entry","body")&gt; &lt;/cffunction&gt; </code>
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

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