<?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>Dan's Drivelings &#187; Mach II</title>
	<atom:link href="http://dan.skaggsfamily.ws/category/mach-ii/feed/" rel="self" type="application/rss+xml" />
	<link>http://dan.skaggsfamily.ws</link>
	<description>Random Thoughts of a Techno-Hermit</description>
	<lastBuildDate>Thu, 09 Sep 2010 02:37:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using the new HTMLHelperProperty in MachII 1.8</title>
		<link>http://dan.skaggsfamily.ws/2009/06/27/using-the-new-htmlhelperproperty-in-machii-1-8/</link>
		<comments>http://dan.skaggsfamily.ws/2009/06/27/using-the-new-htmlhelperproperty-in-machii-1-8/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 19:27:51 +0000</pubDate>
		<dc:creator>Dan Skaggs</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Mach II]]></category>
		<category><![CDATA[Railo]]></category>

		<guid isPermaLink="false">http://dan.skaggsfamily.ws/?p=251</guid>
		<description><![CDATA[I ran into a situation this week while working on a MachII project I&#8217;m doing with my brother that I&#8217;m sure many of you have encountered before. We have our view pages broken up into small chunks that we render inside a &#8220;pod-like&#8221; layout on the screen. Many of these view pages are using a [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a situation this week while working on a <a href="http://www.mach-ii.com" target="_blank">MachII</a> project I&#8217;m doing with my brother that I&#8217;m sure many of you have encountered before. We have our view pages broken up into small chunks that we render inside a &#8220;pod-like&#8221; layout on the screen. Many of these view pages are using a one or more <a href="http://www.jquery.com" target="_blank">jQuery</a> plugins (including <a href="http://cfuniform.riaforge.org/" target="_blank">cfUniform</a>, <a href="http://www.datatables.net" target="_blank">DataTables</a> and <a href="http://fancy.klade.lv" target="_blank">FancyBox</a>) which need the main jQuery library to be included in the header to make them work correctly.  We had been doing something like this in the top of each view that needed jQuery:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfsavecontent</span> variable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;jQueryInit&quot;</span><span style="color: #0000FF;">&gt;</span></span>
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">script</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;text/javascript&quot;</span> <span style="color: #0000FF;">language</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;javascript&quot;</span></span>
<span style="color: #333333;">         <span style="color: #0000FF;">src</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;/javascript/jquery-1.3.2.min.js&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">script</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfsavecontent</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfhtmlhead</span> <span style="color: #0000FF;">text</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#jQueryInit#&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></td></tr></table></div>

<p>This worked perfectly fine for a while, right up until the point where we had two views in the same request that needed jQuery.  If you put the above code in each of the view pages, then only some of your jQuery plugins work because the jQuery javascript file was getting loaded and instantiated multiple times&#8211;wiping out everything that had been configured previously.<br />
<span id="more-251"></span></p>
<p>The natural first &#8220;fix&#8221; for this problem was to only include the above code in the view that would be used first on the page. While that would work in theory, it seriously breaks the notion of encapsulation that we&#8217;re trying to achieve by separating all these views into individual files.  Essentially, you could only ever use a view reliably on one page because you never knew if jQuery had been loaded or not.</p>
<p>I had started to contemplate building some kind of custom listener object and accompanying view to do be able to manage this problem when I remembered reading about the <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/HTMLHelperProperty" target="_blank">HTMLHelperProperty</a> CFC included in MachII 1.8.  After doing some reading, I realized that the solution to my problem was already built right into MachII.</p>
<p>The HTMLHelperProperty is designed to be a &#8220;holding place&#8221; of sorts for anything that you need to dynamically add to the <head> section as you progress through the various steps configured by your <event-handler> for the requested event. It allows you to call different functions to add javascript files, css files, and meta properties to the &#8220;pile&#8221; of things that will be inserted into the <head> section just before the request ends.  For example, to include the jQuery library that we need from the above example, all you have to do is add this bit of code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getProperty<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;html&quot;</span><span style="color: #0000FF;">&#41;</span>.addJavascript<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;jquery-1.3.2.min.js&quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></td></tr></table></div>

<p>The best part is, you can add that same line to EVERY view that needs jQuery and the HTMLHelperProperty CFC will only add it to the <head> tag once.  Yep, you read that right! It intelligently manages duplicate additions so you don&#8217;t wind up clobbering your javascript objects with multiple invocations like we talked about above.</p>
<p>Now, the HTMLHelperProperty CFC isn&#8217;t confined to doing javascript files.  It also can be used to manage CSS files.  Say we have a view that needs to use the DataTables and FancyBox plugins.  Each of those plugins ships with a CSS file that it needs to make things look right.  That&#8217;s no problem either, you can pass in a comma-delimited list of javascript and CSS files (or pass in an array of values as well) like this (extra line breaks added for readability&#8211;you&#8217;ll not want to use them in your code):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getProperty<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;html&quot;</span><span style="color: #0000FF;">&#41;</span>.addJavascript<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;</span>
<span style="color: #333333;">     jquery-1.3.2.min.js, </span>
<span style="color: #333333;">     jquery.dataTables.min.js, </span>
<span style="color: #333333;">     jquery.fancybox-1.2.1.js</span>
<span style="color: #333333;">     &quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getProperty<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;html&quot;</span><span style="color: #0000FF;">&#41;</span>.addStylesheet<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;</span>
<span style="color: #333333;">     datatables.css, </span>
<span style="color: #333333;">     jquery.fancybox.css</span>
<span style="color: #333333;">     &quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></td></tr></table></div>

<p>The other use is to dynamically add <meta> tags to your document.  These are pretty self-explanatory so I&#8217;m not going to go into them here, but refer you to the <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/HTMLHelperProperty" target="_blank">wiki page</a> instead.</p>
<p>You may have noticed that there I&#8217;ve not included any file system paths to the javascript and CSS files in the examples above.  When you configure the property in your MachII config file, you can set the default &#8220;home&#8221; directories for your javascript and CSS files.  In the following example, the path to CSS files is set to &#8220;/css&#8221; and the path to javascript files is set to &#8220;/javascript&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- HTMLHelper Property --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;MachII.properties.HtmlHelperProperty&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;metaTitleSuffix&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot; | MyCompany, Inc.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cacheAssetPaths&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- Defaults to ExpandPath(&quot;.&quot;) --&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!-- &lt;parameter name=&quot;webrootBasePath&quot; value=&quot;/&quot; /&gt; --&gt;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- Defaults to webroot base path + &quot;/js&quot; --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jsBasePath&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/javascript&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- Defaults to webroot base path + &quot;/css&quot; --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;parameter</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;cssBasePath&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/parameters<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Two quick notes on this block of code:  </p>
<ol>
<li>You&#8217;ll notice that I&#8217;ve commented out the parameter named &#8220;webrootBasePath&#8221;. It defaults to the filesystem path equivalent to where your index.cfm page is running which is what I wanted, so I commented it out so as to use the default.</li>
<li>You&#8217;ll also notice a parameter named &#8220;cacheAssetPaths&#8221;. There&#8217;s quite a bit behind this one, but the short version of the story is that, used correctly, this can help your visitors not have to download your javascript and css files every time (using them from the browser cache instead), while still forcing the browser to download the file if you have made any changes.  Refer to the wiki page listed above for a complete description on this feature of the HTMLHelperProperty CFC.</li>
</ol>
<p>One thing that the HTMLHelperProperty doesn&#8217;t do at the moment is allow you to store &#8220;ad-hoc&#8221; javascript code for inclusion in the <head> section.  This would be especially helpful in dealing with jQuery plugins as many of them need to be initialized in script once the document is loaded.  For example, the following script is required to trigger the FancyBox plugin on an image named &#8220;preview&#8221;:</p>
<pre lang="javascript" link="1">
 $(document).ready(function() {
	$("#preview").fancybox();
});
</pre>
<p>It would be really nice to be able to do something like the code below to have your own custom scripts included in the header after the other javascript files are loaded:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfsavecontent</span> variable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;fancyBoxInit&quot;</span><span style="color: #0000FF;">&gt;</span></span>
     $(document).ready(function() {
	$(&quot;#preview&quot;).fancybox();
      });
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfsavecontent</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> getProperty<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;html&quot;</span><span style="color: #0000FF;">&#41;</span>.addScript<span style="color: #0000FF;">&#40;</span> fancyBoxInit, <span style="color: #009900;">&quot;javascript&quot;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></td></tr></table></div>

<p>The only issue I had with the property is that I got an error under under Railo 3.1.015 if I left the .js extension off of each javascript file I wanted to include. The wiki page examples say that you can just put the name of the javascript and css files (minus the extension) into the function, but I wasn&#8217;t able to get it to work unless I included the extensions.  I&#8217;m still experimenting with this to see if it&#8217;s a bug in the property when running under Railo or if it&#8217;s something that I did.</p>
<p>All in all I&#8217;m very impressed with the feature and REALLY happy that I found it before tearing off and creating my own solution.</p>
<p>UPDATE: After looking through the code, I determined that I was getting an error when leaving off the extension of the files because my files had periods in their names other than between the filename and extension. I filed <a href="http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/ticket/336" target="_blank">this bug</a> and submitted a patch. The MachII team reviewed the patch, integrated it into the source and closed the ticket in the space of about 90 minutes.  So, this bug has been resolved in the latest BER version in Subversion.</p>
]]></content:encoded>
			<wfw:commentRss>http://dan.skaggsfamily.ws/2009/06/27/using-the-new-htmlhelperproperty-in-machii-1-8/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>What I&#8217;ve Learned: MVC frameworks are worth it</title>
		<link>http://dan.skaggsfamily.ws/2009/05/15/what-ive-learned-mvc-frameworks-are-worth-it/</link>
		<comments>http://dan.skaggsfamily.ws/2009/05/15/what-ive-learned-mvc-frameworks-are-worth-it/#comments</comments>
		<pubDate>Fri, 15 May 2009 14:21:07 +0000</pubDate>
		<dc:creator>Dan Skaggs</dc:creator>
				<category><![CDATA[Application Design]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Mach II]]></category>
		<category><![CDATA[ModelGlue]]></category>

		<guid isPermaLink="false">http://dan.skaggsfamily.ws/?p=226</guid>
		<description><![CDATA[Most of us that have been around programming for a while have heard the arguments for separating content and layout in our applications numerous times. Likewise, most of us have nodded our heads and generally acknowledged that it&#8217;s a &#8220;good idea&#8221; or something similar. Over the last few days, it&#8217;s really hit home for me [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us that have been around programming for a while have heard the arguments for separating content and layout in our applications numerous times. Likewise, most of us have nodded our heads and generally acknowledged that it&#8217;s a &#8220;good idea&#8221; or something similar. Over the last few days, it&#8217;s really hit home for me why this is such a good idea.</p>
<p>Two of the projects I&#8217;m working on at the moment have had complete user interface updates in the last two weeks.  One is a MachII project I&#8217;m working on with my brother. The other is a ModelGlue project I&#8217;m working on with another client. In each instance, the decision was made that the template that we were using just wasn&#8217;t flexible enough to allow us to easily do what we wanted to so the decision was made to replace it.  I&#8217;m not talking about a simple color scheme change&#8211;both these were radical template changes that changed overall layout containers and content containers as well as the styles for the content elements themselves.</p>
<p>In a traditional, &#8220;spaghetti&#8221; ColdFusion site like we all wrote back in the early days (what I like to call the &#8220;Bad Ole Days&#8221;), this would have been a nightmare to do on a site of any size.  Granted, these two applications were both small- to mid-sized at the moment, but the amount of work and testing required would still have been significant.</p>
<p>Here&#8217;s the real kicker though.  Each of these were done in less than 1 man day&#8217;s worth of effort due to the way MachII and ModelGlue separate the different parts of the process of generating the final HTML page! That&#8217;s just awesome as far as I&#8217;m concerned!</p>
<p>So, for those people that use the argument that MVC frameworks are more work than they&#8217;re worth except in large, enterprise-class applications, I submit that the first time you encounter this situation, you just might change your mind.</p>
<p>*Disclaimer: I know that there are other MVC frameworks out there for ColdFusion and they solve a lot of the same problems that MachII and ModelGlue do. I only mention these two here because they&#8217;re the ones that I worked with directly.</p>
]]></content:encoded>
			<wfw:commentRss>http://dan.skaggsfamily.ws/2009/05/15/what-ive-learned-mvc-frameworks-are-worth-it/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t you love those &#8216;lightbulb&#8217; moments?</title>
		<link>http://dan.skaggsfamily.ws/2007/09/07/dont-you-love-those-lightbulb-moments/</link>
		<comments>http://dan.skaggsfamily.ws/2007/09/07/dont-you-love-those-lightbulb-moments/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 21:14:41 +0000</pubDate>
		<dc:creator>Dan Skaggs</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mach II]]></category>

		<guid isPermaLink="false">http://dan.skaggsfamily.ws/2007/09/07/dont-you-love-those-lightbulb-moments/</guid>
		<description><![CDATA[You ever had one of those &#8216;light-bulb&#8217; moments?]]></description>
			<content:encoded><![CDATA[<p style="font: normal normal normal 12px/normal Helvetica; margin: 0px">You ever had one of those &#8216;light-bulb&#8217; moments?</p>
]]></content:encoded>
			<wfw:commentRss>http://dan.skaggsfamily.ws/2007/09/07/dont-you-love-those-lightbulb-moments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
