<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rabidGadfly &#187; cfajaxproxy</title>
	<atom:link href="http://rabidgadfly.com/tag/cfajaxproxy/feed/" rel="self" type="application/rss+xml" />
	<link>http://rabidgadfly.com</link>
	<description>Simple Solutions to Nagging Coding Problems</description>
	<lastBuildDate>Wed, 19 Oct 2011 13:43:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Using CFAjaxProxy in a Shared Hosting Environment</title>
		<link>http://rabidgadfly.com/2008/09/using-cfajaxproxy-in-a-shared-hosting-environment/</link>
		<comments>http://rabidgadfly.com/2008/09/using-cfajaxproxy-in-a-shared-hosting-environment/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 19:43:47 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[cfajax.js]]></category>
		<category><![CDATA[cfajaxproxy]]></category>
		<category><![CDATA[cfide]]></category>
		<category><![CDATA[cfmessage.js]]></category>
		<category><![CDATA[shared hosting]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=69</guid>
		<description><![CDATA[As I mentioned in my last post (Drag and Drop Sorting with CFAjaxProxy and Script.aculo.us) I&#8217;ve started to use CFAjaxProxy. It&#8217;s been very easy to integrate and I had no problems at all on my local machine. However, after posting my work to a live site my AJAX functionality ceased working. Thanks to Firebug, I [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my last post (<a href="http://www.rabidgadfly.com/?p=68" alt="Read my post! (But finish this one first)">Drag and Drop Sorting with CFAjaxProxy and Script.aculo.us</a>) I&#8217;ve started to use CFAjaxProxy. It&#8217;s been very easy to integrate and I had no problems at all on my local machine. However, after posting my work to a live site my AJAX functionality ceased working.</p>
<p>Thanks to <a href="https://addons.mozilla.org/en-US/firefox/addon/1843" alt="Get Firebug for Firefox!">Firebug</a>, I was able to track down the issue pretty quickly. The cfajax.js and cfmessage.js libraries were failing to load. These files are located in subfolders under the CFIDE folder.</p>
<p>For those unfamiliar with the CFIDE folder, it contains central and core coldfusion files, custom tags, libraries and the ColdFusion administrator. The reason I wasn&#8217;t having the problem locally was because I wasn&#8217;t in a shared hosting environment so CFIDE was right where ColdFusion expected it to be.</p>
<p>In a shared hosting environment, however, ColdFusion looks for CFIDE in the root of the current domain. So, rather than looking in the web server root, it looks in the domain root. For example, if the site I&#8217;m working on is mysite.com, ColdFusion will look for CIDE in http://www.mysite.com/CFIDE/.</p>
<p>While I could make a virtual directory mapping to the existing CFIDE folder, I didn&#8217;t want to expose the ColdFusion Administrator. Instead, I created a new CFIDE folder and copied only the SCRIPTS subfolder into it. I then created a CFIDE virtual directory within the domain which pointed to the new CFIDE folder.</p>
<p>I know many developers have experienced a similar issue with CFFORM, however, that issue can be surmounted with the use of the <a href="http://tutorial157.easycfm.com/" alt="using CFFORM in a hosted environment">scriptsrc parameter</a> which isn&#8217;t available for CFAjaxProxy.</p>
<p>Admittedly, this solution feels a bit lame, but I&#8217;m unaware of any other way around it. If you know of a better way, please leave a comment!</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/09/using-cfajaxproxy-in-a-shared-hosting-environment/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Drag and Drop Sorting with CFAjaxProxy and Script.aculo.us</title>
		<link>http://rabidgadfly.com/2008/08/drag-and-drop-sorting-with-cfajaxproxy-and-scriptaculous/</link>
		<comments>http://rabidgadfly.com/2008/08/drag-and-drop-sorting-with-cfajaxproxy-and-scriptaculous/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 03:39:52 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[coldFusion]]></category>
		<category><![CDATA[script.aculo.us]]></category>
		<category><![CDATA[cfajaxproxy]]></category>
		<category><![CDATA[drag and drop]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://www.rabidgadfly.com/?p=68</guid>
		<description><![CDATA[I made a video player recently containing a list of videos. My client requested the ability to put them in a custom order. It didn&#8217;t take much research to find the functionality in the Script.aculo.us library. The question was, how do I implement it with ColdFusion? I knew I would need AJAX functionality and, up [...]]]></description>
			<content:encoded><![CDATA[<p>I made a video player recently containing a list of videos. My client requested the ability to put them in a custom order. It didn&#8217;t take much research to find the functionality in the <a href="http://script.aculo.us/">Script.aculo.us</a> library. The question was, how do I implement it with ColdFusion?</p>
<p>I knew I would need AJAX functionality and, up to this point, I had always used Rob Gonda&#8217;s AjaxCFC. With the release of ColdFusion 8, however, Adobe introduced <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_a-b_3.html">CFAjaxProxy</a>. I&#8217;d been looking for an opportunity to give it a try and this turned out to be a perfect fit.</p>
<p>Jake Munson of <a href="http://techfeed.net/blog/">Yacoblog</a> posted a <a href="http://techfeed.net/blog/index.cfm/2007/6/18/ColdFusion-8-CFAjaxProxy">great introduction to using CFAjaxProxy</a>. Simple and straight to the point. I had it working in no time.</p>
<p>My next stop was a <a href="http://www.lynchconsulting.com.au/blog/index.cfm/2007/7/15/JavaScript-Drag--Drop">post by Mohammed Irfaan</a> over at the <a href="http://www.lynchconsulting.com.au/blog/">Lynch Consulting Blog</a> which discusses a technique for using ColdFusion to update an underlying table after using Script.aculo.us&#8217;s Drag and Drop functionality.</p>
<p>Here&#8217;s how I put it all together:<br />
<span id="more-68"></span><br />
First, I created a table named videocenter to hold my video records. It looks something like this:<br />
video_uuid &#8211; Unique identifier for each video record<br />
video_title &#8211; Title for the video record<br />
sort_order &#8211; Integer reflecting the order in which the video should be displayed.</p>
<p>Next, I wrote my sortvideos CFC which will loop through the list of videos that my page will send to it, and update the sort_order column to reflect the order in which the video are currently displayed on the screen (more about that later):</p>
<pre><code>
<cfcomponent>
<cffunction name="updateVideoSort" access="remote" returntype="boolean">
	<cfargument name="sortStruct" type="any" required="yes">
	<cfset var q="" />
	<cfset var i=0 />
	<cfloop from="1" to="#ListLen(arguments.sortStruct)#" index="i">
	   <cfquery name="q" datasource="#application.dsn#">
	      UPDATE	videocenter
	      SET 		sort_order = <cfqueryparam value="#i#" cfsqltype="cf_sql_integer">
	      WHERE 	video_uuid = <cfqueryparam value="#trim(listGetAt(arguments.sortStruct, i))#" cfsqltype="cf_sql_varchar" />
	   </cfquery>
	</cfloop>
	<cfreturn true>
</cffunction>
</cfcomponent>
</code></pre>
<p>After downloading and installing the <a href="http://script.aculo.us/">Script.aculo.us</a> JavaScript library, I began to build my page.</p>
<p>I started off by defining the Ajax proxy. This line defines my ColdFusion component (sortvideos) and the JavaScript proxy class that represents the CFC (respond):</p>
<pre><code>
<cfajaxproxy cfc="sortvideos" jsclassname="respond">
</code></pre>
<p>I then included the necessary Script.aculo.us files and the JavaScript function that will call the Ajax method within my ColdFusion component. Note that you may have to alter the path to the JavaScript files depending on where yours are stored:</p>
<pre><code>
<script language="JavaScript" src="js/scriptaculous/lib/prototype.js"></script>
<script language="JavaScript" src="js/scriptaculous/src/scriptaculous.js"></script>

<script type="text/javascript">
function resort() {
	var r= new respond();
	var orderList = '';
	//call the echo function from the CFC
	orderedNodes = document.getElementById("sortable_list").getElementsByTagName("li");
	for (var i=0;i < orderedNodes.length;i++) {
		orderList += orderedNodes[i].getAttribute('recordid') + ', ';
	}
	r.updateVideoSort(orderList);
  }
</script>
</code></pre>
<p>When called, orderedNodes will become an array of the LI elements within the "sortable_list" UL element defined below. The elements in the array will be in the order in which the list appears on the page. This is the list that gets sent to the updateVideoSort method within my sortvideos CFC above.</p>
<p>Next, I loop through my video records and display the videos in an unordered list. I add an ID to the UL named "sortable_list" and I add a custom attribute to each LI element (recordid) containing video_uuid from my videos table. After that, I place a submit button that will call my resort() function when clicked.</p>
<pre><code>
<cfset qvideos = videosService.getVideos() />
<ul id="sortable_list" style="cursor: move; list-style:none;">
<cfoutput query="qvideos">
<li recordid="#video_uuid#">#video_title#</li>

</cfoutput>
</ul>
<input type="button" onclick="resort();" value="Submit new order" />
</code></pre>
<p>Finally, a last bit of required JavaScript to make the Script.aculo.us magic happen. Note that "sortable_list" is the id I gave to my UL element above.<br />
<script language="JavaScript">
	Sortable.create("sortable_list");
</script></p>
<p>Now I have a list of videos from my videocenter table which can be ordered using drag and drop functionality a la Netflix.</p>
<p>-rG</p>
]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2008/08/drag-and-drop-sorting-with-cfajaxproxy-and-scriptaculous/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

