<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2" -->
<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/"
	>

<channel>
	<title>blog.widget-labs.com</title>
	<link>http://blog.widget-labs.com</link>
	<description></description>
	<pubDate>Fri, 07 Sep 2007 22:02:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>
	<language>en</language>
			<item>
		<title>Split Column DataGrid</title>
		<link>http://blog.widget-labs.com/2007/09/07/split-column-datagrid/</link>
		<comments>http://blog.widget-labs.com/2007/09/07/split-column-datagrid/#comments</comments>
		<pubDate>Fri, 07 Sep 2007 22:00:06 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/2007/09/07/split-column-datagrid/</guid>
		<description><![CDATA[If you need to extend datagrid to support grouping of column headers together, feel free to use or extend the following code.
A picture worth a thousand words,  so better check out demo and src.
Note: Source code is based on Alex&#8217;s sample: http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html
(I extended it to support more then 2 columns per grouping)
]]></description>
			<content:encoded><![CDATA[<p>If you need to extend datagrid to support grouping of column headers together, feel free to use or extend the following code.</p>
<p>A picture worth a thousand words,  so better check out <a href="http://widget-labs.com/flex/MultipleSplitColumns//dg.html">demo</a> and <a href="http://widget-labs.com/flex/MultipleSplitColumns/srcview/">src</a>.</p>
<p>Note: Source code is based on Alex&#8217;s sample: <a href="http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html">http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html</a></p>
<p>(I extended it to support more then 2 columns per grouping)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/09/07/split-column-datagrid/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Code generation: Java Beans to AS</title>
		<link>http://blog.widget-labs.com/2007/06/17/code-generation-java-beans-to-as/</link>
		<comments>http://blog.widget-labs.com/2007/06/17/code-generation-java-beans-to-as/#comments</comments>
		<pubDate>Sun, 17 Jun 2007 18:19:56 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/2007/06/17/code-generation-java-beans-to-as/</guid>
		<description><![CDATA[If you have java backend that provides data to your flex application and you want to have matching data transfer object between java and flex you may end up with a lot of copy and paste from java to as.
For example you may have java bean that defines a user:


public class User {
   [...]]]></description>
			<content:encoded><![CDATA[<p>If you have java backend that provides data to your flex application and you want to have matching data transfer object between java and flex you may end up with a lot of copy and paste from java to as.</p>
<p>For example you may have java bean that defines a user:</p>
<p class="code">
<pre>
public class User {
    private String name;
    private int id;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
</p class="code">
</pre>
<p>When passing this object between java and flex (via webservices or fds) you want to have matching action script class, something like :</p>
<p class="code">
<pre>
public class User {
  public var name:String;
  public var id:Number;
}
</p class="code">
</pre>
<p>It looks like a perfect task for automation, given the amount of good tools for parsing and templating it would not take a lot of time to create a small application that can do transformation. I decided to use <a href="http://www.antlr.org">ANTLR v3.0</a> for parsing java code and <a href="http://www.stringtemplate.org/">StringTemplate </a>for generating action script code. Both of these products are well integrated and easy to use. </p>
<p>ANTLR comes with java grammar, so all you need to do is to update grammar file to add actions that would capture information related to transformation, and later pass this info to StringTemplate to generate result code.</p>
<p>Here is <a href='http://blog.widget-labs.com/wp-content/uploads/2007/06/javabeans2as.zip' title='Binary'>binary</a> that can be run from command line:</p>
<p class="code">
<pre>
java -jar ASGen.jar c:/javacode/src data.A C:/ascode/src
</p class="code">
</pre>
<p>you need to specify java src, full name of the java bean (including packages) and output folder for action script code.</p>
<p>But even better reason to use code generator is to fully automate the whole remote service layer. You can base it on java code (or wsdl for webservices or whatever else that allows to do mapping to flex code).</p>
<p>Here is the source <a href="http://ext.stuff.googlepages.com/Ws2AsGen.zip">code </a>for java beans to as generator (it also includes code I use for service layer generations)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/06/17/code-generation-java-beans-to-as/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting url parameters in Flex</title>
		<link>http://blog.widget-labs.com/2007/04/01/getting-url-parameters-in-flex/</link>
		<comments>http://blog.widget-labs.com/2007/04/01/getting-url-parameters-in-flex/#comments</comments>
		<pubDate>Sun, 01 Apr 2007 23:49:49 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/2007/04/01/getting-url-parameters-in-flex/</guid>
		<description><![CDATA[Recently I needed to access url parameters from Flex code. Here is an example how to do it. I am using ExternalInterface to get access to the browser (you cannot get parameters from Application.application.url).
Pay attention to the following note from doc:
Note: When embedding SWF files within an HTML page, make sure that the id and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to access url parameters from Flex code. Here is an example how to do it. I am using ExternalInterface to get access to the browser (you cannot get parameters from Application.application.url).<br />
Pay attention to the following note from doc:</p>
<p>Note: When embedding SWF files within an HTML page, make sure that the id and name attributes of the <object> and <embed> tags do not include characters such as: . (period), -, +, *, /, and \.</p>
<p>I would also add additional character: &#8216;{&#8217; - by mistake I use application name &#8216;app{&#8217; and because of this could not access ExternalInterface (any method invocation returns null in this case)</p>
<p>You can use the following code to parse url and get dictionary that contains param names as key and param values as values.</p>
<pre>

<a name="l1">function getUrlParamateres():Dictionary
{
   var urlParams:Dictionary = new Dictionary(); 

   var fullUrl:String = ExternalInterface.call(&#8217;eval&#8217;,'document.location.href&#8217;); 

   var paramStr:String = fullUrl.split(&#8217;?')[1];
   if (paramStr != null)
    {
        var params:Array = paramStr.split(&#8217;&amp;&#8217;);
        for (var i:int = 0; i &lt; params.length; i++)
       {
            var kv:Array = params[i].split(&#8217;=');
            urlParams[kv[0]] = kv[1];
        }
    } 

    return urlParams;
}</a>
</pre>
<p>Note: Probably better to use regex to replace parsing code to more simple statement (as long as regex is not too complex).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/04/01/getting-url-parameters-in-flex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Review of Garmin Edge 305</title>
		<link>http://blog.widget-labs.com/2007/04/01/review-of-garmin-edge-305/</link>
		<comments>http://blog.widget-labs.com/2007/04/01/review-of-garmin-edge-305/#comments</comments>
		<pubDate>Sun, 01 Apr 2007 02:38:51 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[bike]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/2007/04/01/review-of-garmin-edge-305/</guid>
		<description><![CDATA[If you are looking to get more out of your biking make sure to try Garmin Edge 305 bicycle computer. Despite the hefty price tag it delivers a lot of value and make rides more enjoyable.
Edge 305 provides the following high level features:

typical bike data (speed, distance, cadence and ect)
heart rate monitor (heart rate zones)
map [...]]]></description>
			<content:encoded><![CDATA[<p>If you are looking to get more out of your biking make sure to try Garmin Edge 305 bicycle computer. Despite the hefty price tag it delivers a lot of value and make rides more enjoyable.</p>
<p>Edge 305 provides the following high level features:</p>
<ul>
<li>typical bike data (speed, distance, cadence and ect)</li>
<li>heart rate monitor (heart rate zones)</li>
<li>map (rudimentary)</li>
<li>altitude graph</li>
<li>virtual partner</li>
</ul>
<p>Stuff I like about device:</p>
<p>Very easy to install. Not need to know tire radius, the device would use GPS data to calculate all required information (and in most cases would use GPS to calculate your route anyway)</p>
<p>Automatic heart rate zone calculation based on your Max heart rate.</p>
<p>Ability to upload all info about route (map and data) into the computer or web site to see how you did and where exactly you biked. You can sign up (free account) into <a href="http://trail.motionbased.com/trail">http://trail.motionbased.com/trail</a> and upload data and see other peoples routes. (I only wish this site used Flash/Flex technology instead of html/ajax to make it more interactive and usable).</p>
<p>Here are the list of screen shots:</p>
<p>Data that shows speed, distance, cadence and so on (there are very big list to choose from and your can always configure screen the way you like)</p>
<p><a href='http://blog.widget-labs.com/wp-content/uploads/2007/04/img_4738-3.JPG' title='img_4738-3.JPG'><img src='http://blog.widget-labs.com/wp-content/uploads/2007/04/img_4738-3.JPG' alt='img_4738-3.JPG' /></a></p>
<p>Map (Mostly useless, but on rare occasions when you get lost can be very helpful and you would be thankful even for this lousy map)</p>
<p><a href='http://blog.widget-labs.com/wp-content/uploads/2007/04/img_4739-2.JPG' title='img_4739-2.JPG'><img src='http://blog.widget-labs.com/wp-content/uploads/2007/04/img_4739-2.JPG' alt='img_4739-2.JPG' /></a></p>
<p>Altitude (close to useless IMO)</p>
<p><a href='http://blog.widget-labs.com/wp-content/uploads/2007/04/img_4740-2.JPG' title='img_4740-2.JPG'><img src='http://blog.widget-labs.com/wp-content/uploads/2007/04/img_4740-2.JPG' alt='img_4740-2.JPG' /></a></p>
<p>Edge also provide some training (virtual partner) feature, but so far I didn&#8217;t use it, so cannot comment if it&#8217;s any good.</p>
<p>The only somewhat bad comment I have - battery life. For most cases as long as you remember to charge it&#8217;s not a problem. But it&#8217;s somewhat different from my previous bike computer that didn&#8217;t require any charging at all.</p>
<p>Overall, if you like to bicycle (road or mountain) and somewhat geeky, Garmin Edge 305 would give you more data than you ever need.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/04/01/review-of-garmin-edge-305/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Short update on RemoteList implementation</title>
		<link>http://blog.widget-labs.com/2007/03/13/short-update-on-remotelist-implementation/</link>
		<comments>http://blog.widget-labs.com/2007/03/13/short-update-on-remotelist-implementation/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 02:17:19 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/2007/03/13/short-update-on-remotelist-implementation/</guid>
		<description><![CDATA[Just short update for RemoteList  post: 
I noticed strange bug when you try to move scroll bar up and down - scrollbar position and data page may become unsynchronized (meaning that if scroll down all the way and then scroll up all the way you would not arrive at the same set of rows) [...]]]></description>
			<content:encoded><![CDATA[<p>Just short update for <a href="http://blog.widget-labs.com/2007/01/21/new-version-of-remotelist-ilist-implementation-that-support-paging/">RemoteList </a> post: </p>
<p>I noticed strange bug when you try to move scroll bar up and down - scrollbar position and data page may become unsynchronized (meaning that if scroll down all the way and then scroll up all the way you would not arrive at the same set of rows) - not sure if it&#8217;s something specific to my RemoteList implementation or the way DataGrid.getItemAt() works. </p>
<p>In any case the easiest way to avoid the problem is to ask DataGrid not to update rows while scrolling by using liveScrolling property:</p>
<p><code><mx:DataGrid  liveScrolling="false" ... /></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/03/13/short-update-on-remotelist-implementation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Welcome to my new blog home</title>
		<link>http://blog.widget-labs.com/2007/03/10/11/</link>
		<comments>http://blog.widget-labs.com/2007/03/10/11/#comments</comments>
		<pubDate>Sat, 10 Mar 2007 06:46:30 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[other]]></category>

		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/?p=11</guid>
		<description><![CDATA[This is new home for my blog previously located at: http://stackoverflowexception.blogspot.com/
blogspot.com provided more or less good service but not enough control over styling and editor (the biggest annoyance was with inserting code snippets into the blog).
This new blog is powered by WordPress software and hopefully woud provide better functionality.
]]></description>
			<content:encoded><![CDATA[<p>This is new home for my blog previously located at: <a href="http://stackoverflowexception.blogspot.com/" title="http://stackoverflowexception.blogspot.com/" target="_blank">http://stackoverflowexception.blogspot.com/</a></p>
<p>blogspot.com provided more or less good service but not enough control over styling and editor (the biggest annoyance was with inserting code snippets into the blog).</p>
<p>This new blog is powered by WordPress software and hopefully woud provide better functionality.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/03/10/11/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cascade List component</title>
		<link>http://blog.widget-labs.com/2007/03/05/cascade-list-component/</link>
		<comments>http://blog.widget-labs.com/2007/03/05/cascade-list-component/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 06:36:00 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/?p=10</guid>
		<description><![CDATA[I would like to share a Cascade List component that allows to work with tree like structures:

It should accept the same data you can pass to flex Tree control but would display it by using List elements stacked together. You can sign up for listItemSelected event to listen for selection and control style by styleName [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to share a Cascade List component that allows to work with tree like structures:</p>
<p><img src="http://bp2.blogger.com/_vwPd8Vp49Sc/Re0OocvG6hI/AAAAAAAAABI/0z_zGmNsnH4/s400/CascadeList.JPG" id="BLOGGER_PHOTO_ID_5038699646168787474" style="margin: 0px auto 10px; display: block; text-align: center" border="0" /></p>
<p>It should accept the same data you can pass to flex Tree control but would display it by using List elements stacked together. You can sign up for <em>listItemSelected</em> event to listen for selection and control style by <em>styleName</em> property. See link to an example below for more details.</p>
<p>You can see a demo <a href="http://ext.stuff.googlepages.com/CascadeListExample.html">here</a>.</p>
<p>Source code and example can be found <a href="http://ext.stuff.googlepages.com/CascadeList.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/03/05/cascade-list-component/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Logging and Debugging deployed Flex applications</title>
		<link>http://blog.widget-labs.com/2007/02/24/logging-and-debugging-deployed-flex-applications/</link>
		<comments>http://blog.widget-labs.com/2007/02/24/logging-and-debugging-deployed-flex-applications/#comments</comments>
		<pubDate>Sat, 24 Feb 2007 17:51:00 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/?p=9</guid>
		<description><![CDATA[I want to share my experience with troubleshooting Flex problem in deployed environment. I am working on a application that uses web service as back end. I do development and basic testing in Flex Builder so I can run debugger and see trace outputs.But lately I decided to try run my app from web container [...]]]></description>
			<content:encoded><![CDATA[<p>I want to share my experience with troubleshooting Flex problem in deployed environment. I am working on a application that uses web service as back end. I do development and basic testing in Flex Builder so I can run debugger and see trace outputs.But lately I decided to try run my app from web container (tomcat). The first problem I encountered was my <span class="blsp-spelling-error" id="SPELLING_ERROR_0">login</span> screen doesn&#8217;t work. I pressed <span class="blsp-spelling-error" id="SPELLING_ERROR_1">login</span> and nothing happened. I have code that uses Application.application.url parameter to figure out host site and based on <span class="blsp-spelling-error" id="SPELLING_ERROR_2">url</span> decide where to locate web services. In local debug environment I use <span class="blsp-spelling-error" id="SPELLING_ERROR_3">hardcoded</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_4">url</span> (and it works fine), in deployed one I have code that construct <span class="blsp-spelling-error" id="SPELLING_ERROR_5">url</span> dynamically (and obviously it wasn&#8217;t working well).</p>
<p>What should I do?</p>
<p>Luckily Flex Builder provides an easy way to run remote application (loaded from web container) in debug mode. First you need to make sure that you used -debug=true flag when you compiled your application. Once you done it, you can create a new debug run configuration in Flex Builder and specify <span class="blsp-spelling-error" id="SPELLING_ERROR_6">url</span> of deployed application and related project:</p>
<p><img src="http://bp3.blogger.com/_vwPd8Vp49Sc/ReEItwGtzGI/AAAAAAAAAA8/dpqK07Hbb0k/s400/debug.JPG" id="BLOGGER_PHOTO_ID_5035315440477129826" style="margin: 0px auto 10px; display: block; text-align: center" border="0" /></p>
<p>Now you just need to set breakpoints, press debug and see why something doesn&#8217;t work.</p>
<p>Remote debug mode is quite convenient if you have full control over environment. But eventually your application would be deployed in customer site and most likely you would not be able to use debugger to trace down your problem.</p>
<p>To address this problem you need to make sure you have enough log statements in your code that would help to pinpoint the problem so make sure you are aware about mx.logging.* package.</p>
<p>It&#8217;s very similar to java logging <span class="blsp-spelling-error" id="SPELLING_ERROR_7">api</span> and should not take long to figure out. The main caveat is that to use default trace facility(mx.logging.targets.TraceTarget) you need to run debug version of flash player. <span class="blsp-spelling-error" id="SPELLING_ERROR_8">TraceTarget</span> allows you to output message to system.out (eclipse console) or <span class="blsp-spelling-error" id="SPELLING_ERROR_9">flashlog</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_10">txt</span>. To make sure that <span class="blsp-spelling-error" id="SPELLING_ERROR_11">flashlog</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_12">txt</span> is created, you need to check that you have mm.<span class="blsp-spelling-error" id="SPELLING_ERROR_13">cfg</span> in your user home directory (in my case I didn&#8217;t have mm.<span class="blsp-spelling-error" id="SPELLING_ERROR_14">cfg</span> created by installer). If you don&#8217;t have mm.<span class="blsp-spelling-error" id="SPELLING_ERROR_15">cfg</span> - create it in C:\Documents and Settings\{<span class="blsp-spelling-error" id="SPELLING_ERROR_16">username</span>}\( obviously this window specific, check manual for <span class="blsp-spelling-error" id="SPELLING_ERROR_17">linux</span> path) and populate with parameter you want to use for ex.:</p>
<p><span class="blsp-spelling-error" id="SPELLING_ERROR_18">ErrorReportingEnable</span>=1<br />
<span class="blsp-spelling-error" id="SPELLING_ERROR_19">TraceOutputFileEnable</span>=1<br />
<span class="blsp-spelling-error" id="SPELLING_ERROR_20">MaxWarnings</span>=100</p>
<p>Now you would be able to see <span class="blsp-spelling-error" id="SPELLING_ERROR_21">flashlog</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_22">txt</span> in c:\Documents and Settings\{<span class="blsp-spelling-error" id="SPELLING_ERROR_23">username</span>}\Application Data\<span class="blsp-spelling-error" id="SPELLING_ERROR_24">Macromedia</span>\Flash Player\Logs\.</p>
<p>Most likely you would not be able to use debug flash player in customer environment. You can write your own extension of flex logging classes to make sure you can capture trace event somehow. But the easier way to start with already existing flex logging extension &#8220;trace panel&#8221; from Adobe Flex Exchange (or directly from author&#8217;s site <a href="http://www.faratasystems.com/?page_id=45">http://www.faratasystems.com/?page_id=45</a>) . It provide log <span class="blsp-spelling-error" id="SPELLING_ERROR_25">capturer</span> win32 application and source code for <span class="blsp-spelling-error" id="SPELLING_ERROR_26">AbstractTarget</span> that communicates with the win32 app and shows log statement when using none-debug version of flash player.</p>
<p>Hope this was helpful. If know some other techniques that can be used in Flex to simplify problem troubleshooting let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/02/24/logging-and-debugging-deployed-flex-applications/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Handling Web Service exception in Flex code</title>
		<link>http://blog.widget-labs.com/2007/02/15/handling-web-service-exception-in-flex-code/</link>
		<comments>http://blog.widget-labs.com/2007/02/15/handling-web-service-exception-in-flex-code/#comments</comments>
		<pubDate>Thu, 15 Feb 2007 16:00:00 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/?p=8</guid>
		<description><![CDATA[In this post I&#8217;ll explain how to propogate exception details from Web Services into Flex. I am using java XFire web service implementation but similar steps can be applied to different ws implementations.
Let assume you defined a web servie method:
public String getSomething() throws ClientException
where ClientException would contain information like exception id and message.
If the method [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll explain how to propogate exception details from Web Services into Flex. I am using java XFire web service implementation but similar steps can be applied to different ws implementations.</p>
<p>Let assume you defined a web servie method:</p>
<p>public String getSomething() throws ClientException</p>
<p>where ClientException would contain information like exception id and message.</p>
<p>If the method throw an exception, on Flex side you want to extract id and message to present it to user.To do this in Flex we can use standard &#8220;fault&#8221; handler (I assume you know how to call web service from Flex so I would go into much details there)</p>
<p class="code">
<pre>
  service.doSomething.addEventListener("result", responder.result);
  service.doSomething.addEventListener("fault", responder.fault);
  service.doSomething();</pre>
<p>Here we use already defined web service (service) and assign &#8220;result&#8221; handler to handle normal flow and &#8220;fault&#8221; handler to handler any exception, including our own ClientException.</p>
<p>responder.fault may look like:</p>
<p class="code">
<pre>
public function fault(info:Object):void {

  var ns:Namespace = new Namespace("http://www.acme.com");
  default xml namespace = ns;

  var xml:XML = new XML(info.fault.faultDetail);

  if (xml.id[0] == "123") {
    show(xml.message[0]);
  }
}</pre>
<p>Here we acccess Flex provided info object that includes fault member variable. Using fault var we can access exception details (in this case id and message) and process this data.</p>
<p>So far nothing really special done on Flex side.</p>
<p>Now let&#8217;s look how to implement server side. I would not go into details how expose web service in XFire (you can find this info in XFire docs). Instead let&#8217;s focus on Flex specific moments. The most important one is that Flex would not process SOAP fault message if HTTP status code other then 200. Here is excerpt from Flex manual:</p>
<p>&gt; &#8220;On web browsers, when a service returns any status code other than 200,<br />
&gt; Adobe Flash Player<br />
&gt; cannot read the body of the response. If the status code is 500 and the<br />
&gt; body contains a<br />
&gt; fault, there is no way to get to the fault. The proxy works around this<br />
&gt; issue by forcing the<br />
&gt; status code for faults to 200; the player passes the body of the<br />
&gt; response along with the<br />
&gt; fault intact. &#8221;</p>
<p>It means that we need to add a code on server side to ensure that response code is equal to 200 when we throw an exception. When exception thrown from XFire HTTP status code would be 500 (web services standard implies it), so we need to create a servlet filter that would set HTTP status code to 200 to allow Flex web service engine access SOAP body.</p>
<p>This is also pretty standard stuff, you would need to define filter and associate it with XFire servlet in web.xml (you can find more info on filter <a href="http://java.sun.com/products/servlet/Filters.html#72674">here</a>):</p>
<p class="code">
<pre>
<a title="l1" name="l1"></a><span class="s0">&lt;?</span><span class="s1">xml version=</span><span class="s3">&#8220;1.0&#8243; </span><span class="s1">encoding=</span><span class="s3">&#8220;UTF-8&#8243;</span><span class="s0">?&gt;
</span><a title="l2" name="l2"></a><span class="s2">&lt;</span><span class="s4">web-app </span><span class="s1">xmlns=</span><span class="s3">&#8220;http://java.sun.com/xml/ns/j2ee&#8221; </span><span class="s1">xmlns:xsi=</span><span class="s3">&#8220;http://www.w3.org/2001/XMLSchema-instance&#8221; </span><span class="s1">version=</span><span class="s3">&#8220;2.4&#8243; </span><span class="s1">xsi:schemaLocation=</span><span class="s3">&#8220;http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&#8221;</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l3" name="l3"></a>  <span class="s2">&lt;</span><span class="s4">servlet</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l4" name="l4"></a>    <span class="s2">&lt;</span><span class="s4">servlet-name</span><span class="s2">&gt;</span><span class="s5">XFireServlet</span><span class="s2">&lt;/</span><span class="s4">servlet-name</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l5" name="l5"></a>    <span class="s2">&lt;</span><span class="s4">servlet-class</span><span class="s2">&gt;</span><span class="s5">org.codehaus.xfire.transport.http.XFireConfigurableServlet</span><span class="s2">&lt;/</span><span class="s4">servlet-class</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l6" name="l6"></a>    <span class="s2">&lt;</span><span class="s4">load-on-startup</span><span class="s2">&gt;</span><span class="s5">0</span><span class="s2">&lt;/</span><span class="s4">load-on-startup</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l7" name="l7"></a>  <span class="s2">&lt;/</span><span class="s4">servlet</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l8" name="l8"></a>  <span class="s2">&lt;</span><span class="s4">servlet-mapping</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l9" name="l9"></a>    <span class="s2">&lt;</span><span class="s4">servlet-name</span><span class="s2">&gt;</span><span class="s5">XFireServlet</span><span class="s2">&lt;/</span><span class="s4">servlet-name</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l10" name="l10"></a>    <span class="s2">&lt;</span><span class="s4">url-pattern</span><span class="s2">&gt;</span><span class="s5">/services/*</span><span class="s2">&lt;/</span><span class="s4">url-pattern</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l11" name="l11"></a>  <span class="s2">&lt;/</span><span class="s4">servlet-mapping</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l12" name="l12"></a>  <span class="s2">&lt;</span><span class="s4">filter</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l13" name="l13"></a>   <span class="s2">&lt;</span><span class="s4">filter-name</span><span class="s2">&gt;</span><span class="s5">ExceptionFilter</span><span class="s2">&lt;/</span><span class="s4">filter-name</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l14" name="l14"></a>   <span class="s2">&lt;</span><span class="s4">filter-class</span><span class="s2">&gt;</span><span class="s5">com.acme.filter.ExceptionFilter</span><span class="s2">&lt;/</span><span class="s4">filter-class</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l15" name="l15"></a>  <span class="s2">&lt;/</span><span class="s4">filter</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l16" name="l16"></a>  <span class="s2">&lt;</span><span class="s4">filter-mapping</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l17" name="l17"></a>   <span class="s2">&lt;</span><span class="s4">filter-name</span><span class="s2">&gt;</span><span class="s5">ExceptionFilter</span><span class="s2">&lt;/</span><span class="s4">filter-name</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l18" name="l18"></a> <span class="s2">&lt;</span><span class="s4">servlet-name</span><span class="s2">&gt;</span><span class="s5">XFireServlet</span><span class="s2">&lt;/</span><span class="s4">servlet-name</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l19" name="l19"></a>  <span class="s2">&lt;/</span><span class="s4">filter-mapping</span><span class="s2">&gt;</span><span class="s0">
</span><a title="l20" name="l20"></a><span class="s2">&lt;/</span><span class="s4">web-app</span><span class="s2">&gt;</span></pre>
<p><a title="l20" name="l20"></a>Exception filter would like:</p>
<p class="code">
<pre><a title="l20" name="l20"></a>
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class ExceptionFilter implements Filter {

  public void destroy() {
  }

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
  throws IOException, ServletException {

  HttpServletResponse httpResponse = (HttpServletResponse) response;
  ExceptionHttpServletResponseWrapper wrapper = new ExceptionHttpServletResponseWrapper(httpResponse);

  chain.doFilter(request, wrapper);
}

public void init(FilterConfig arg0) throws ServletException {
}

}</pre>
<p><a title="l20" name="l20"></a>And you to define HttpServletResponsWrapper that would control setStatus() method to ensure that status code is 200.</p>
<p class="code">
<pre><a title="l20" name="l20"></a>
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public class ExceptionHttpServletResponseWrapper extends
  HttpServletResponseWrapper {

  public ExceptionHttpServletResponseWrapper(HttpServletResponse response) {
   super(response);
  }

  @Override
  public void setStatus(int statusCode) {
   if (statusCode == 500) {
     super.setStatus(200);
   }
  }
}</pre>
<p><a title="l20" name="l20"></a>The above code can be used for any web service implementation.</p>
<p><a title="l20" name="l20"></a>We still need to add some specific way XFire handles user&#8217;s exception. One way to it is to create a custom ClientExceptionDetails that contain id and message.</p>
<p class="code">
<pre><a title="l20" name="l20"></a>
public class ClientExceptionDetails {

 private int id;
 private String message;

 public ClientExceptionDetails(int id, String message) {
  super();
  this.id = id;
  this.message = message;
 }

 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getMessage() {
  return message;
 }
 public void setMessage(String message) {
  this.message = message;
 }
}</pre>
<p><a title="l20" name="l20"></a>And make sure that ClientException uses this info:</p>
<p class="code">
<pre><a title="l20" name="l20"></a>
import javax.xml.namespace.QName;

import org.codehaus.xfire.fault.FaultInfoException;
import org.codehaus.xfire.fault.XFireFault;

public class ClientException extends FaultInfoException  {

 private ClientExceptionDetails faultDetail;

 public ClientException(String message, ClientExceptionDetails detail) {
  super(message);

  this.faultDetail = detail;
 }

 public ClientExceptionDetails getFaultInfo() {
  return faultDetail;
 }

 public static QName getFaultName() {
  return new QName(&#8221;http://www.acme.com&#8221;, &#8220;ClientException&#8221;);
 }
}</pre>
<p><a title="l20" name="l20"></a>(Check XFire doc for more info about FaultInfoException)</p>
<p><a title="l20" name="l20"></a>That&#8217;s all, now when you throw ClientException, XFire would use ClientExceptionDetails to populat SOAP body with id and message that you can extract later on Flex side from fault.faultDetail.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/02/15/handling-web-service-exception-in-flex-code/feed/</wfw:commentRss>
		</item>
		<item>
		<title>New version of RemoteList (IList implementation that support paging)</title>
		<link>http://blog.widget-labs.com/2007/01/21/new-version-of-remotelist-ilist-implementation-that-support-paging/</link>
		<comments>http://blog.widget-labs.com/2007/01/21/new-version-of-remotelist-ilist-implementation-that-support-paging/#comments</comments>
		<pubDate>Sun, 21 Jan 2007 20:05:00 +0000</pubDate>
		<dc:creator>rd</dc:creator>
		
		<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://blog.widget-labs.com/?p=7</guid>
		<description><![CDATA[This is another post about implementation of remote list for Adobe Flex 2.
As I mentioned in previous post Flex framework provides ItemPendingError exception mechanism to use when collection data is not available. For example DataGrid component provides support for this exception. I didn&#8217;t look too deeply in DataGrid code but my understanding that if ItemPendingError [...]]]></description>
			<content:encoded><![CDATA[<p>This is another post about implementation of remote list for Adobe Flex 2.</p>
<p>As I mentioned in previous post Flex framework provides ItemPendingError exception mechanism to use when collection data is not available. For example DataGrid component provides support for this exception. I didn&#8217;t look too deeply in DataGrid code but my understanding that if ItemPendingError is thrown DataGrid would retry load the data by providing hooks into the ItemPendingError. I believe that all List based components should behave similary.</p>
<p>Given all these built-in support I realized it&#8217;s much better to rely on ItemPendingError mechanism then event notification as I did in my previous post.</p>
<p>New version of RemoteList is based on old one with one exception - instead of dispatching CollectionEventKind.REPLACE to notifiy view (DataGrid), I throw ItemPendingException.</p>
<p>There are 3 main pieces:<br />
IRemoteDataSet - interface that defines how to get remote data (RemoteDataSet a sample implementation)<br />
RemoteList - class that uses IRemoteDataSet to get data and ItemPendingError mechanism to notify DataGrid when data is available<br />
ItemPendingErrorEx - extends ItemPendingError to add dataReady/error methods.</p>
<p>I extended ItemPendingException by adding new method:</p>
<p class="code">
<pre>
  public function dataReady(data:Object):void
  {
   if (responders)
   {
    responders.forEach(
     function(item:IResponder, index:int, arr:Array):void
     {
      item.result(data);
     });
   }
  }</pre>
<p>(I am somewhat surprised that similar method is not included by default)</p>
<p>This method iterates through all IResponders and notifies them when data is ready. IResponders would be added by DataGrid component so I don&#8217;t need to do anything else here.</p>
<p>I also updated miss() method in the RemoteList class:</p>
<p class="code">
<pre>/**
   * Called when we need to load a new page of data and throws a new exception for first request or
   * rethrows already created exception if data loading already in progress.
   */
  public function miss(index:int):void
  {
   var item:Object = localData[index];
   if (item == null)
   {
    var page : Number = Math.floor(index / pageSize);

    if (pagesPending[page] == null)
    {
     remoteDataSet.loadData(page, pageSize);

     var loadingEvent:Event = new Event("Loading");
     dispatchEvent(loadingEvent);  

     var error:ItemPendingErrorEx = new ItemPendingErrorEx("Loading Data ...");
     pagesPending[page] = error;
     throw error;
    } else
    {
     throw pagesPending[page];
    }
   }
  }</pre>
<p>The method would throw an ItemPendingErrorEx to let notify DataGrid that data is loading.</p>
<p>When data is ready onDataReady() method is called by RemoteDataSet class:</p>
<p class="code">
<pre>
  public function onDataReady(loadedData:Object):void
  {
   var result:Array = loadedData.result[0]["value"].toArray();
   var page:int = loadedData.result[1]["value"];

   var error:ItemPendingErrorEx = pagesPending[page];

   pagesLoaded[page] = true;
   var beginIdx : Number = page * pageSize;

   localData.splice.apply(localData, [beginIdx, result.length].concat(result));

   if (cleanData)
   {
    cleanInvisiblePages(page);
   }

   trace("localData is updated: " + beginIdx + "-" + (beginIdx + result.length) );              

   error.dataReady(result);

   if (isDataInit == false)
   {
    isDataInit = true;
    dispatchResetEvent(); // make columns are initialized
   }

   var dataReadyEvent:Event = new Event("DataReady");
   dispatchEvent(dataReadyEvent);
  }</pre>
<p>Here ItemPendingErrorEx.dataReady method is called that in turn would call DataGrid&#8217;s supplied listener to notify that data is ready and DataGrid can redraw the rows.</p>
<p code="code">You can download all code from <a href="http://ext.stuff.googlepages.com/RemoteListSample.rar">here</a>.</p>
<p>(Still need to add support for sorting)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.widget-labs.com/2007/01/21/new-version-of-remotelist-ilist-implementation-that-support-paging/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
