<?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>GridLinked to RUX &#187; Cairngorm</title>
	<atom:link href="http://www.gridlinked.info/Flex/cairngorm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridlinked.info</link>
	<description>Patterns with Flex, RUX, and software</description>
	<lastBuildDate>Fri, 26 Feb 2010 22:18:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex i18n with LocalizationMaps &#8211; Video Tutorial &amp; Source</title>
		<link>http://www.gridlinked.info/flex-i18n-with-localizationmaps-video-tutorial-source/</link>
		<comments>http://www.gridlinked.info/flex-i18n-with-localizationmaps-video-tutorial-source/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 20:41:34 +0000</pubDate>
		<dc:creator>thomasb</dc:creator>
				<category><![CDATA[Cairngorm]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[Mate]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[behavior]]></category>
		<category><![CDATA[l10n]]></category>
		<category><![CDATA[resourceManager]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.gridlinked.info/?p=576</guid>
		<description><![CDATA[In this Part 2 on Flex l10n solutions, I provide (1) an architecture diagram, (2) a localized Registration demo application, and (3) a video tutorial on why and how to use LocalizationMaps for your own custom solutions. Also included is the source code for both the Registration demo and the "l10n LocaleMap" library.<br /><div><img src="http://www.gridlinked.info/wp-content/plugins/gd-star-rating/gfx.php?value=9.8" /></div><div>Rating: 9.8/<strong>10</strong> (8 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>
In a previous article, I blogged about <span style="text-decoration: underline;"><a href="http://www.gridlinked.info/amazing-i18n-solutions-for-flex-3-4/"></span> Flex i18n and an &#8220;Inversion of Control&#8221;</a> (IOC) approach to radically simplify localization issues within your Flex solutions. That article discussed the issues with the current, traditional localization implementations [used in Flex applications] and then presented the new LocalizationMap solution. </p>
<p>In this Part 2 on Flex l10n solutions, I offer a video tutorial, a demo of a Registration application localized to support Spanish and English, and an architecture diagram of LocalizationMap usages. </p>
<p>Also included with the live Flex demo is <a href="http://github.com/ThomasBurleson/l10nInjection_Samples/archives/master" style="text-decoration: underline; color: rgb(153, 0, 0);">source code</a> for both the demo and the l10n LocaleMap library.</p>
<p>Below is a screencast video tutorial; in which I provide a narrated overview of the issue involved with enabling your Flex application to support multiple languages (and locales). I also present LocalizationMaps as a great solution to easily and rapidly provide l10n (localization) features within your custom Flex apps. </p>
<div class="img aligncenter" style="width:422px;">
	<a rel="lightbox;height=490;width=650" href="http://www.gridlinked.info/flash/podcasts/Podcast_Flexi18nLocalizationMaps.html" style="color: #999999;" ><img src="/images/2009/12/PodcastPlayer.jpg" alt="Figure 3: Video Tutorial" width="422" height="317" /></a>
	<div>Figure 1: Video Tutorial (click to play)</div>
</div>
<p>Note that the video/podcast tutorial may take 5-10 seconds for streaming to start.</p>
<p>Shown below is a live demo of the localized Registration application. This application has l10n (localization) support for English and Spanish.  In the live demo, select the Spanish or English flags to change the current locale. Watch what happens to all the strings and styles. </p>
<p>Be sure to complete the registration fields and click the Register button to see the view state changes to show a localized Thank you with fullname and email parameters (sounds confusing&#8230; just try it)!</p>
<div class="img aligncenter" style="width:278px;">
	<a rel="lightbox;height=700;width=600" href="http://www.gridlinked.info/flash/l10nRegistration/RegistrationDemo_i18n.html" style="color: #eaeaea;" ><img src="/images/2009/12/RegistrationDemo_l10n.png" alt="LocalizationMap Usage Diagram" width="278" height="335" /></a>
	<div>Figure 2: RegistrationDemo w/ Locales (click to launch)</div>
</div>
<p>Simply right-click to access the source code for both the demo and the l10n LocaleMap library. Or click here to <a href="http://github.com/ThomasBurleson/l10nInjection_Samples/archives/master" style="text-decoration: underline; color: rgb(153, 0, 0);">download</a> the source code.  Before you review the source code, however, I encourage you to review the architecture diagram shown Figure 3 and listen to the Screencast tutorial (Figure 1). </p>
<p>
Here is a high-level diagram that illustrates how the LocalizationMap is used within your custom applications. I encourage you to conceptualize the LocalizationMap as a plug-in to your application&#8230; an extension that is completely transparent (hidden) from your presentation/GUI layer.</p>
<div class="img aligncenter" style="width:490px;">
	<a rel="lightbox;height=592;width=981" href="http://www.gridlinked.info/images/2009/12/localemap_overview.png" style="color: #ffffff;" ><img src="/images/2009/12/localemap_overview.png" alt="LocalizationMap Usage Diagram" width="490" height="296" /></a>
	<div>Figure 3: LocalizationMap Usage Diagram (click to zoom)</div>
</div>
<br /><div><img src="http://www.gridlinked.info/wp-content/plugins/gd-star-rating/gfx.php?value=9.8" /></div><div>Rating: 9.8/<strong>10</strong> (8 votes cast)</div><br /><hr />
<p><small>© Thomas Burleson for <a href="http://www.gridlinked.info">GridLinked to RUX</a>, 2009.   
&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;  
<a href="http://feedburner.google.com/fb/a/mailverify?uri=GridlinkedToRux&amp;loc=en_US"><span style="color:#900">Subscribe by Email</span></a> |
<a href="mailto:ThomasBurleson@GMail.com">Contact Author</a> 	&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;
<a href="http://www.gridlinked.info/flex-i18n-with-localizationmaps-video-tutorial-source/">Permalink</a> |    
<a href="http://www.gridlinked.info/flex-i18n-with-localizationmaps-video-tutorial-source/#comments">20 comments</a>
<br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.gridlinked.info/flex-i18n-with-localizationmaps-video-tutorial-source/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Cairngorm Secret Tip #3: Responders for View Notifications</title>
		<link>http://www.gridlinked.info/cairngorm-secret-tip-3-responders-for-view-notifications/</link>
		<comments>http://www.gridlinked.info/cairngorm-secret-tip-3-responders-for-view-notifications/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 21:57:50 +0000</pubDate>
		<dc:creator>thomasb</dc:creator>
				<category><![CDATA[Cairngorm]]></category>
		<category><![CDATA[Fireworks]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[event dispatching]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://www.gridlinked.info/?p=287</guid>
		<description><![CDATA[In the real-world appliations, the data binding solutions espoused by Cairngorm MVC are not always sufficient. Sometimes Views dispatch business events to request data that should be available only to that specific instance of the calling view. So how does a Cairngorm presentation layer view "subscribe" for post event-processing notifications from the Command? The remarkably easy solution is to use Responders as notification mechanisms to allow Commands to notify Views… just like the way Delegates notify Commands in the control layers.<br /><div><img src="http://www.gridlinked.info/wp-content/plugins/gd-star-rating/gfx.php?value=9.5" /></div><div>Rating: 9.5/<strong>10</strong> (42 votes cast)</div><br />]]></description>
			<content:encoded><![CDATA[<p>As Flex continues to grow as the choice RIA technology, many developers start investigating and apply Java design patterns to Flex implementations. Similar to Java Struts, Cairngorm is a  MVC (Model-View-Controller)  framework &#8211; endorsed by Adobe &#8211; that is widely popular within the community.  </p>
<p>One of issues that frequently confuses, blocks, or complicates Cairngorm implementations is the issue of &#8220;view notifications&#8221;. Every Cairngorm developer ask the following question at some point: <span style="color:#AB0000;font-size:1.1em;">How should the Cairngorm business layer best communicate with the Presentation layer?</span> </p>
<p><br/>Review Figure 1 which illustrates the recommended relationships between the view and control layers:</p>
<p><img src="http://www.gridlinked.info/images/2009/04/figure1_mvc.png" alt="Flex Cairngorm MVC " width="642" height="280" class="alignleft size-full wp-image-317" /></p>
<ul>
<li>Model is a repository for data</li>
<li>Views support user interactions and announce user gestures as dispatched events to Controllers</li>
<li>Controllers employ commands to process dispatched events</li>
<li>Commands are responsible for using Delegates to talk to the server, and updating model data (client side)</li>
<li>Views use data binding to &#8220;watch&#8221; Model data changes and self-update to dipslay formatted data. </li>
</ul>
<div class="qa"><span class="question">This sounds great. So what is the problem?</span></div>
<p>Commands are supposed to use the Model layer as the mediator between business and presentation layers. In Flex, data bindings and change watchers allow views to <em>watch</em> data models. When data is modified, hidden propertyChange events are dispatched from Models to Views and the View uses event listeners to self-update.  This is the basic premise of the Flex Cairngorm MVC framework. </p>
<p>In real-world applications, data binding solutions espoused by Cairngorm MVC are not always sufficient; since such solutions require views to watch for data changes. Some times, however, watching for data changes is complicated&#8230; perhaps the data is not globally available. Sometimes the view [that dispatches the business event] is requesting data that should  be available <em>only</em> to that specific instance of the calling view; and should not be stored in global repositories. Sometimes, we do not care so much about the data&#8230; but instead we want to execute custom code when the event succeeds and finishes.</p>
<p>PureMVC and traditional Cairngorm solutions require complex code and design patterns to solve these situations. </p>
<ul>
<li> ViewLocators could be used to try to <em>lookup</em> an instance of a view. (Requires coupling to specific view classes from the business layer&#8230;. BAD!)
<li> Views could employ/register private view controllers with the front controller, </li>
<li> Command could dispatch new &#8220;notify view&#8221; events thru the front Controller to the view controller </li>
</ul>
<p>The above approaches create a proliferation of view controllers and is useful ONLY when multiple views want to listen to the same event and be notified simultaneously. Please note that in such rare situtations, a custom event-bridge or a traditional data binding approach would be more practical [but that is another article]. In fact, in most scenarios, the view simply wants the notification directly and exclusively (only to its instance). For these situations, there is a simpler &#8211; and better &#8211; solution to the ViewController complexity. </p>
<ul>
<li>What if we cannot easily use global data models and view data binding?</li>
<li>What if we do not want to create an hierarchy of bindable properties simply to deliver data to deeply nested child views?
<li>How can we deliver data directly to a view instance without storing that data in the ModelLocator hierarchy?</li>
<li>And&#8230; if the View invokes a Command [via event dispatching] and Command/Delegate pairs process server data, how can the Command deliver the processed results back to the View only?</li>
</ul>
<p>The remarkably easy solution is to use Responders as notification mechanisms to allow Commands to <em>notify</em>  Views&#8230; just like the way Delegates notify Commands [See Cairngorm Secret Tip #2: Data Transformations within Delegates]. To understand the proposed solution, consider the Cairngorm approach where a Command instance employs a Delegate class as &#8220;API facade&#8221; to remote data services. </p>
<p>The command instance <em>submits</em> itself [or a proxy to itself] as a responder to the delegate. The delegate, in turn, simply uses the specified responder to direct dataservice responses directly to back to the command.  This allows the Command to receive <em>callbacks</em> from the Delegate or the Server. In fact, advance this same approach is used at the Delegate level to allow Delegate instances to intercept server responses, transform data, and <em>then</em> notify/pass the modified data back to the Command.</p>
<div class="qa">
With Responders, post-command notifications can be delivered agnostically to any caller [View] that has provided a ResultEvent handler and a FaultEvent handler.
</div>
<p>Using Responders, a Command can submit itself as a callback to specific Delegate calls. Views can effectively do the same with Commands. Figure 2 below illustrates this process or queueing of responses. The queue builds with (1) View waits for a response from the Command, (2) the Commands waits on the Delegate, and (3) the Delegate waits on the Server. The queue unwinds after (4) the server responds, (5) Delegate notifies the command, (6) the Command notifies the view.  Using a Responder proxy, the view is notified after the actual dataservice request/response and after Command processing; see Step (6) in Figure 2. </p>
<p><img src="http://www.gridlinked.info/images/2009/04/figure2_viewnotifications.png" alt="View Notifications using Responders" width="642" height="269" class="alignleft size-full wp-image-318" /></p>
<p><br/> &nbsp;</p>
<div class="qa"><span class="question">How exactly does the view provide a Responder to the Command  ?</span></div>
<p>Well, when we dispatch business events to commands, we create custom events. So we simply need to transport a Responder instance along with the normal event information that is dispatched to the Cairngorm control layer. If all custom events have constructors with optional responder arguments then we have a built-in mechanism to support callbacks from Commands.</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
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> mx.rpc
<span style="color: #000000;">&#123;</span>
<span style="color: #3f5fbf;">/**</span>
<span style="color: #3f5fbf;">&nbsp;*  This interface provides the contract for any service</span>
<span style="color: #3f5fbf;">&nbsp;*  that needs to respond to remote or asynchronous calls.</span>
<span style="color: #3f5fbf;">&nbsp;*/</span>
<span style="color: #0033ff; font-weight: bold;">public</span> interface IResponder
<span style="color: #000000;">&#123;</span>
	<span style="color: #3f5fbf;">/**</span>
<span style="color: #3f5fbf;">	 *  This method is called by a service when the return value</span>
<span style="color: #3f5fbf;">	 *  has been received. </span>
<span style="color: #3f5fbf;">	 *  While &lt;code&gt;data&lt;/code&gt; is typed as Object, it is often</span>
<span style="color: #3f5fbf;">	 *  (but not always) an mx.rpc.events.ResultEvent.</span>
<span style="color: #3f5fbf;">	 */</span>
<span style="display:block;background-color: #ffc;">	<span style="color: #339966; font-weight: bold;">function</span> result<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>;</span>&nbsp;
	<span style="color: #3f5fbf;">/**</span>
<span style="color: #3f5fbf;">	 *  This method is called by a service when an error has been received.</span>
<span style="color: #3f5fbf;">	 *  While &lt;code&gt;info&lt;/code&gt; is typed as Object it is often</span>
<span style="color: #3f5fbf;">	 *  (but not always) an mx.rpc.events.FaultEvent.</span>
<span style="color: #3f5fbf;">	 */</span>
	<span style="color: #339966; font-weight: bold;">function</span> fault<span style="color: #000000;">&#40;</span><span style="color: #004993;">info</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com.grdlinked.samples.control.events <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">Event</span>;
    <span style="color: #0033ff; font-weight: bold;">import</span> mx.rpc.IResponder;
    <span style="color: #0033ff; font-weight: bold;">import</span> com.universalmind.cairngorm.events.UMEvent;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LoadUserDetails extends UMEvent <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #6699cc; font-weight: bold;">var</span> EVENT_ID <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;loadUserDetailsBySSN&quot;</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ssn      <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span>;
        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> password <span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span>; 
&nbsp;
        <span style="color: #009900;">// Constructor </span>
<span style="display:block;background-color: #ffc;">        <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LoadUserDetails<span style="color: #000000;">&#40;</span> ssn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>,</span>                                    password<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span>,
                                    callbacks<span style="color: #000000; font-weight: bold;">:</span>IResponder=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span>EVENT_ID, callbacks, <span style="color: #0033ff; font-weight: bold;">true</span>, <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">this</span>.ssn      = ssn;
            <span style="color: #0033ff; font-weight: bold;">this</span>.password = password;
&nbsp;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>For the examples in the post, we use a custom event <CairngormEvent> <em>LoadUserDetailsEvent</em> class that accepts an optional &#8220;responder&#8221; parameter.  Using a SSN and password the view requests user details from the control layer. The control/business layer may elect to lookup the user in a client-side cache or call the server. The business layer is responsible for all these details and the presentation/UI layer need not worry. And the view does NOT know anything about who handles the event or how the event is processed. This &#8220;separation of concerns&#8221; is what MVC is all about.  </p>
<p>When the event is processed by the command, the command can temporarily cache the view responder or callback. Sometime later &#8211; after the asynchronous data service call responds &#8211; the following can happen:</p>
<ol>
<li> the command can use the dataservice response to update the ModelLocator directly, trigger databindings to update, and</li>
<li>  the command can forward the dataservice response or any OTHER data to the cached responder. Command::notifyCaller() is the method used to provide view notifications.</li>
</ol>
<div class="qa">
<span class="question">Do all my views have to implement the IResponder interface or &#8211; even worse &#8211; extend a custom parent class?&#8221;</span>
</div>
<p>If your views want to implement the IResponder interface, each one of your views would need to include public result() and fault() functions:</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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Canvas 	<span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;400&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;300&quot;</span> 
		implements=<span style="color: #990000;">&quot;mx.rpc.IResponder&quot;</span>
		xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
		<span style="color: #0033ff; font-weight: bold;">import</span> mx.rpc.IResponder;
		<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Alert;
&nbsp;
     <span style="color: #009900;">// Methods required by the IResponder interface		</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> result<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            btnLoad.<span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
      <span style="color: #000000;">&#125;</span>
      <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> fault<span style="color: #000000;">&#40;</span><span style="color: #004993;">data</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            Alert.<span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">message</span><span style="color: #000000;">&#41;</span>;
            btnLoad.<span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
      <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">// Private methods invoked by child controls		</span>
      <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loadUserDetails<span style="color: #000000;">&#40;</span>ssn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
            btnLoad.<span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;	<span style="color: #009900;">// disable button while waiting for a response.</span>
&nbsp;
            <span style="color: #009900;">// Load the user details for the specified user</span>
            <span style="color: #009900;">//NOTE how this view will be the responder...</span>
<span style="display:block;background-color: #ffc;">            <span style="color: #6699cc; font-weight: bold;">var</span> callbacks <span style="color: #000000; font-weight: bold;">:</span> IResponder = <span style="color: #0033ff; font-weight: bold;">this</span> <span style="color: #0033ff; font-weight: bold;">as</span> IResponder;</span>            <span style="color: #6699cc; font-weight: bold;">var</span> event <span style="color: #000000; font-weight: bold;">:</span> LoadUserDetailsEvent = <span style="color: #0033ff; font-weight: bold;">new</span> LoadUserDetailsEvent<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;435-34-1283&quot;</span>, <span style="color: #990000;">&quot;anonymous&quot;</span>, callbacks<span style="color: #000000;">&#41;</span>;
		  event.<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span>  <span style="color: #000000;">&#41;</span>;   <span style="color: #009900;">// Cairngorm events self-dispatch directly to the business layer; </span>
      <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;btnLoad&quot;</span> label=<span style="color: #990000;">&quot;Load User&quot;</span> textAlign=<span style="color: #990000;">&quot;center&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;145&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;149&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;loadUserDetails()&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;147&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>In our example the view needs to know when the results are available; since the load button is disabled until the business layer [and server] responds .</p>
<p>The above code sample shows, unfortunately, how each of your custom views would need to be modified to work as view responders. When the command finishes, it would call something like caller.result(). Unfortunately, the signature of the result() function is ambiguous and does not document which event triggered the result. In contrast a method like onResult_loadUserDetails() explicit documents its purpose.</p>
<div id="pullquote-con">If you see any code like that show above, then please slap the developer immediately! </div>
<p>After a thorough slapping, ask that developer this question: <span style="color:#AB0000"><br />
&#8220;What if I had two buttons that each dispatched separate business events and each needed separate response handlers? How could the result() function be the common event handler for both events? Would I have to somehow detect &#8211; inside the result() method &#8211; which event is responding?&#8221;<br />
</span></p>
<p>As you can see, this solution rapidly creates nasty code and rapidly produces nasty, convoluted, unmanageable code.</p>
<p>So instead of requiring an abomination of view interfaces or view inheritance (which is even worse), the view will instead create an instance of a Responder class that will serve as a proxy responder class. The Responder class will <em>redirect</em> result() and fault() calls to methods that we specify.   Let us look at some code for clarity. Below we see an example of custom view component created to load and display user details.</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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Canvas 	<span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;400&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;300&quot;</span> 
		xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
		<span style="color: #0033ff; font-weight: bold;">import</span> mx.rpc.IResponder;
		<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Alert;
		<span style="color: #0033ff; font-weight: bold;">import</span> mx.rpc.events.FaultEvent;
		<span style="color: #0033ff; font-weight: bold;">import</span> mx.rpc.<span style="color: #004993;">Responder</span>;
&nbsp;
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loadUserDetails<span style="color: #000000;">&#40;</span>ssn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
          <span style="color: #009900;">// Load the user details for the specified user</span>
<span style="display:block;background-color: #ffc;">          <span style="color: #6699cc; font-weight: bold;">var</span> callbacks <span style="color: #000000; font-weight: bold;">:</span> IResponder           = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Responder</span><span style="color: #000000;">&#40;</span>onResults_loadUserDetails, onFault_loadUserDetails<span style="color: #000000;">&#41;</span>;</span>          <span style="color: #6699cc; font-weight: bold;">var</span> event     <span style="color: #000000; font-weight: bold;">:</span> LoadUserDetailsEvent = <span style="color: #0033ff; font-weight: bold;">new</span> LoadUserDetailsEvent<span style="color: #000000;">&#40;</span>user.ssn, user.password, callbacks<span style="color: #000000;">&#41;</span>;
&nbsp;
          btnLoad.<span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;	<span style="color: #009900;">// disable button while waiting for a response.</span>
          event.<span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span>  <span style="color: #000000;">&#41;</span>;	<span style="color: #009900;">// Cairngorm events can self-dispatch to the business layer.	  </span>
     <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #009900;">// ***************************************************</span>
     <span style="color: #009900;">// Private EventHandlers for the loadUserDetails()</span>
     <span style="color: #009900;">// ***************************************************</span>
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onResuls_loadUserDetails<span style="color: #000000;">&#40;</span>user<span style="color: #000000; font-weight: bold;">:</span>UserVO<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
          <span style="color: #009900;">// The SSN and password were authenticated; here are user details</span>
          _user = <span style="color: #000000; font-weight: bold;">!</span>user <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #0033ff; font-weight: bold;">new</span> UserVO<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">:</span> user;
          btnLoad.<span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
     <span style="color: #000000;">&#125;</span>	
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onFault_loadUserDetails<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span>FaultEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
          Alert.<span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span>event.<span style="color: #004993;">message</span><span style="color: #000000;">&#41;</span>;
          btnLoad.<span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
     <span style="color: #000000;">&#125;</span>
&nbsp;
     <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _user <span style="color: #000000; font-weight: bold;">:</span> UserVO = <span style="color: #0033ff; font-weight: bold;">new</span> UserVO<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;			
&nbsp;
    <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Text <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Please enter your credentials to edit your account:&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;16&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;30&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>FormItem label=<span style="color: #990000;">&quot;FullName:&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;23&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;208&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>  
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{_user.fullName}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span> 
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>FormItem<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>FormItem label=<span style="color: #990000;">&quot;SSN:&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;54&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;104&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>  
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>TextInput id=<span style="color: #990000;">&quot;txtSSN&quot;</span>  <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;{_user.ssn}&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;129&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span> 
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>FormItem<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>FormItem label=<span style="color: #990000;">&quot;Password:&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;23&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;70&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span> 
		<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>TextInput id=<span style="color: #990000;">&quot;txtPassword&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span> 
	<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>FormItem<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button id=<span style="color: #990000;">&quot;btnLoad&quot;</span> label=<span style="color: #990000;">&quot;Load User&quot;</span> textAlign=<span style="color: #990000;">&quot;center&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;145&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;149&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;loadUserDetails()&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;147&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Canvas<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<div class="qa">
<span class="question">Question: And how is the view notified of the response from the server (after the command finishes)? </span>
</div>
<p>Commands &#8211; after the processing is finished &#8211; will trigger any cached IResponders::result() methods to notify the sender [View] of the event. </p>
<p>In the code example above, look at line 15  where we use a Responder instance to act as a proxy for the functions that we want to call. The Responder class does NOT know any details about the view itself. It simply has functions that may be called upon an event response. For a successful response, the view wants <span style="color:#0070C0;">onResults_loadUserDetails()</span> to be called. Likewise for failures, the view wants <span style="color:#0070C0;">onFault_loadUserDetails()</span> to be called. With responders, the view essentially provides event handlers for Command post-processing. </p>
<p>To summarize the above code snippet as psuedo-code, you (a) use a responder proxy wrapper class, (b) package the responder instance inside the event, and (c) extend the command base class to support the caching of the callback/view responder. And voila&#8217; you are done!</p>
<p>This is VERY clean:</p>
<ol>
<li> your views are still standard mxml or as classes with aggregates and composite controls,</li>
<li>  event dispatching is the same [with an optional callback] and</li>
<li>  you do NOT have to create crude view controllers to handle view notifications</li>
<li>  each view instance can have its OWN, separate callback</li>
<li>  views can then support  modal operations, undos, reverts, commits, etc&#8230; completely independent of each other.</li>
<li>  you can dispatch as many business events as desired; each with their own event/response handler methods.
</ol>
<p>Better yet, this functionality is built into the Cairngorm Extensions (CGX) using both the Callback and the mx.rpc.Responder classes.  CGX is an open-source extension to cairngorm. If you are interested in this and other Cairngorm extensions provide comments to this blog or or visit <a href="http://code.google.com/p/flexcairngorm/">Google Cairngorm Extensions</a>. </p>
<br /><div><img src="http://www.gridlinked.info/wp-content/plugins/gd-star-rating/gfx.php?value=9.5" /></div><div>Rating: 9.5/<strong>10</strong> (42 votes cast)</div><br /><hr />
<p><small>© Thomas Burleson for <a href="http://www.gridlinked.info">GridLinked to RUX</a>, 2009.   
&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;  
<a href="http://feedburner.google.com/fb/a/mailverify?uri=GridlinkedToRux&amp;loc=en_US"><span style="color:#900">Subscribe by Email</span></a> |
<a href="mailto:ThomasBurleson@GMail.com">Contact Author</a> 	&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;	&nbsp;
<a href="http://www.gridlinked.info/cairngorm-secret-tip-3-responders-for-view-notifications/">Permalink</a> |    
<a href="http://www.gridlinked.info/cairngorm-secret-tip-3-responders-for-view-notifications/#comments">41 comments</a>
<br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.gridlinked.info/cairngorm-secret-tip-3-responders-for-view-notifications/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
	</channel>
</rss>
