<?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>software, bourbon, and the banjo &#187; Transfer ORM</title>
	<atom:link href="http://www.cansado.org/category/coldfusion/transfer-orm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cansado.org</link>
	<description>musings on software development, usually while inebriated</description>
	<lastBuildDate>Mon, 09 Jan 2012 02:13:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>TransferObject Decorators and the Mach-II Event-Bean</title>
		<link>http://www.cansado.org/2009/11/07/transferobject-decorators-and-the-mach-ii-event-bean/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=transferobject-decorators-and-the-mach-ii-event-bean</link>
		<comments>http://www.cansado.org/2009/11/07/transferobject-decorators-and-the-mach-ii-event-bean/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 00:22:03 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Mach-II]]></category>
		<category><![CDATA[Transfer ORM]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=15</guid>
		<description><![CDATA[If you&#8217;ve been following this blog, you know I&#8217;ve been trying to get TransferObjects to function as Mach-II event-beans. A problem that has been solved, I&#8217;m happy to say, with the help of Transfer Decorators. The approach I took was to supplement my TransferObjects with methods that would only be used by the event-bean during [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been following this blog, you know I&#8217;ve been trying to get TransferObjects to function as Mach-II event-beans. A problem that has been solved, I&#8217;m happy to say, with the help of <a href="http://www.transfer-orm.com">Transfer</a> <a href="http://docs.transfer-orm.com/wiki/Writing_Decorators.cfm">Decorators</a>.</p>
<p>The approach I took was to supplement my TransferObjects with methods that would only be used by the event-bean during form-to-bean population, and only for non-string methods. For example, my Course object has a &#8216;cost&#8217; associated with it, which is a numeric. I added the following to my Course decorator:</p>

<div class="wp_syntax"><div 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;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getCostString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</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;">cfreturn</span> getCost<span style="color: #0000FF;">&#40;</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;">cffunction</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;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setCostString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</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;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;costString&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</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;">cfif</span> <span style="color: #0000FF;">isNumeric</span><span style="color: #0000FF;">&#40;</span>arguments.costString<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> setCost<span style="color: #0000FF;">&#40;</span>arguments.costString<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;">cfif</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;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Note that the functions and argument both reference a <code>costString</code> instead of just a <code>cost</code>. The <code>costString</code> will only be used by the event-bean population code, which means you need to modify your form:input tag as well:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">label</span> <span style="color: #0000FF;">for</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;costString&quot;</span><span style="color: #0000FF;">&gt;</span></span>Cost to Participants<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">label</span><span style="color: #0000FF;">&gt;</span></span>
      $<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>form:input path<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;costString&quot;</span><span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Once this code is in place, the event-bean works like a charm, populating all the fields you need without throwing those pesky errors due to string-to-numeric or string-to-date mistypes. It even works for checkboxes:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">      <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">label</span> <span style="color: #0000FF;">for</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatString&quot;</span><span style="color: #0000FF;">&gt;</span></span>Education Format<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">label</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;">cfloop</span> <span style="color: #0000FF;">query</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatQuery&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>form:checkbox path<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatString&quot;</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#educationFormatQuery.id#&quot;</span><span style="color: #0000FF;">/&gt;</span></span><span style="color: #0000FF;">#educationFormatQuery.format#</span>
      <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>


<div class="wp_syntax"><div 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;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getEducationFormatString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</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> <span style="color: #000000; font-weight: bold;">var</span> returnString <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</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> <span style="color: #000000; font-weight: bold;">var</span> formats <span style="color: #0000FF;">=</span> getEducationFormatsArray<span style="color: #0000FF;">&#40;</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;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ArrayLen(formats)#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</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;">cfif</span> returnString <span style="color: #0000FF;">neq</span> <span style="color: #009900;">&quot;&quot;</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> returnString <span style="color: #0000FF;">=</span> returnString <span style="color: #0000FF;">&amp;</span> <span style="color: #009900;">&quot;,&quot;</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;">cfif</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> returnString <span style="color: #0000FF;">=</span> returnString <span style="color: #0000FF;">&amp;</span> formats<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span>.getId<span style="color: #0000FF;">&#40;</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;">cfloop</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;">cfreturn</span> returnString<span style="color: #0000FF;">/&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</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;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setEducationFormatString&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;void&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</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;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;educationFormatString&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</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> <span style="color: #000000; font-weight: bold;">var</span> array <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ListToArray</span><span style="color: #0000FF;">&#40;</span>arguments.educationFormatString<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> clearEducationFormats<span style="color: #0000FF;">&#40;</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;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ArrayLen(array)#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</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> addEducationFormats<span style="color: #0000FF;">&#40;</span>getTransfer<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>.get<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;gorgon.EducationFormat&quot;</span>, array<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#41;</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;">cfloop</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;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Since I&#8217;m using decorators anyway, why not just overwrite the methods for setting/getting numeric/date/checkboxes and be done with it? Well, I figured the solutions for populating event-beans and regular TransferObject usage might be completely different depending on the complexity of the bean; why go cluttering up a bean with extraneous method overloading and type-checking when I could just add a couple of methods that are only specifically used by one instance of the framework, and then ignored the rest of the time? Basically it&#8217;s a trade-off, and neither side is well explored territory so I erred on what I thought was the side of caution. I&#8217;m completely open to trying it the other way if the data suggest I made a design mistake.</p>
<p>So there you have it, after three iterations of attempts I&#8217;m finally binding forms to TransferObjects without writing too much code. Now we get to move out of the kiddy-pool and start coding for real. Hopefully this project will go forward more smoothly and will be much more maintainable now that I have what I consider a clean design from the start.</p>
<p>We shall see.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/07/transferobject-decorators-and-the-mach-ii-event-bean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You Can&#8217;t Proxy TransferObjects in ColdSpring</title>
		<link>http://www.cansado.org/2009/11/05/you-cant-proxy-transferobjects-in-coldspring/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=you-cant-proxy-transferobjects-in-coldspring</link>
		<comments>http://www.cansado.org/2009/11/05/you-cant-proxy-transferobjects-in-coldspring/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 20:04:55 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[ColdSpring]]></category>
		<category><![CDATA[Transfer ORM]]></category>

		<guid isPermaLink="false">http://www.cansado.org/?p=9</guid>
		<description><![CDATA[In an attempt to use TransferObjects as event-beans I created a class called TransferObjectBindingAdvice that would wrap around the setter methods called by the Mach-II event-beans, to be installed and called via the AOP hooks in ColdSpring. I had high hopes that this proxied object would be able to take the place of the more [...]]]></description>
			<content:encoded><![CDATA[<p>In an attempt to <a href="http://www.cansado.org/2009/11/04/using-transferobjects-as-mach-ii-event-beans/">use TransferObjects as event-beans</a> I created a class called <code>TransferObjectBindingAdvice</code> that would wrap around the setter methods called by the Mach-II <code>event-bean</code>s, to be installed and called via the AOP hooks in ColdSpring. I had high hopes that this proxied object would be able to take the place of the more advanced data binding hooks that I would&#8217;ve liked to see in the upcoming 1.9 release of Mach-II.</p>
<p>I wanted to be able to verify that setters expecting a Date object would get a valid date string, sure; but I also wanted to be able to bind more complex objects to the <code>event-bean</code>s. For example, I could pass in the TransferFactory in the aspect&#8217;s declaration in the ColdSpring configuration file, and use it on a setter for a many-to-many relationship which would be represented as a checkbox group on a form. Simply loop through the list of IDs passed as that checkbox group and build your relationship, all before the controller gets called.</p>
<p>Unfortunately <a href="http://corfield.org/blog/index.cfm?">Sean Corfield</a> pointed out this approach was technically impossible. He told me that TransferObjects are generated dynamically and the methods only exist at runtime, so they can&#8217;t be proxied by ColdSpring.</p>
<p>Which brings me back to square one. What is the best way to handle form-binding cleanly in Mach-II? Do I need to create model objects and be done with it? Should I use Transfer decorators? Should I give up hope of using TransferObjects, the <code>event-bean</code> command, and the &lt;form&gt; taglib in harmony?</p>
<p>Nah. Next up: decorators!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cansado.org/2009/11/05/you-cant-proxy-transferobjects-in-coldspring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
