Spry Demo Updated

This post is more than 2 years old.

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

http://ray.camdenfamily.com/spry/blog3.cfm

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;cfelse&gt;
			&lt;cfset txt = xmlFormat(txt)&gt;
		&lt;/cfif&gt;
		&lt;cfset s = s & "&lt;" & col & "&gt;" & txt & "&lt;/" & col & "&gt;"&gt;

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

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

&lt;cfreturn s&gt;

</cffunction>

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;

</cffunction>

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, 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

Archived Comments

Comment 1 by Will posted on 6/23/2006 at 8:36 AM

It's nice to know a bug I posted about is getting fixed so quickly :) Any idea when the next release will be? I had originally built this for a project that is now past deadline and that I had to rip the spry out of because of the pagination/sort issue and go with a different, much less efficient process. I'd love to be able to add the spry back in to my project by the next release.

Comment 2 by Raymond Camden posted on 6/23/2006 at 3:35 PM

Will, I can't really comment on that. However, let me ping my contact to see if you can use the fix. I mean, technically, you could just view source on my code and download right now. I assume you are aware of that. :)

Comment 3 by Tof posted on 12/3/2008 at 6:22 AM

the demo url link can't be resolved ...
but i think it would great .

Comment 4 by Raymond Camden posted on 12/3/2008 at 6:59 AM