<?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>Olympic Arts</title>
	<atom:link href="http://www.olympicarts.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.olympicarts.nl</link>
	<description>Everything should be made as simple as possible, but not simpler</description>
	<lastBuildDate>Sun, 26 Feb 2012 11:20:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Android read file from URL</title>
		<link>http://www.olympicarts.nl/2011/02/24/android-read-file-from-url/</link>
		<comments>http://www.olympicarts.nl/2011/02/24/android-read-file-from-url/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 15:13:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[HttpClient]]></category>
		<category><![CDATA[IOException]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=164</guid>
		<description><![CDATA[Access an URL on Android and prevent Authentication error &#038; HTTP response code: 401 on public URLS]]></description>
			<content:encoded><![CDATA[<h2>How to read a file from the internet</h2>
<p>While coding y next app for Android, I found out that I needed to read files from URL locations and saven them on my Android device.<br />
I searched for the first sample and put that code to work in my app. That was a quick disappointment. It dit not work and it gave me the message:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; java.<span style="color: #006633;">io</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a><span style="color: #339933;">:</span> Server returned HTTP response code<span style="color: #339933;">:</span> <span style="color: #cc66cc;">401</span> <span style="color: #000000; font-weight: bold;">for</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URL</span></a><br />
&nbsp; DefaultRequestDirector<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5824</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> Authentication error<span style="color: #339933;">:</span> Unable to respond to any of these challenges<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></div></div>
<p>I did not know what to make of this, since my file on the net is not protected by authentication. A lot of searching on the web did not reveal any solution to my problem (only solutions where you had to authenticate).</p>
<p>After long hours of searching I found a workaround for my problem. Just send in some dummy authentication and it will work.</p>
<h2>HTTPClient / UrlConnection example</h2>
<p>Here is my sample of my workaround</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; URI _url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #009900;">&#40;</span>location<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; HttpGet httpget <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpGet<span style="color: #009900;">&#40;</span>_url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; DefaultHttpClient httpclient <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DefaultHttpClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; httpclient.<span style="color: #006633;">getCredentialsProvider</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setCredentials</span><span style="color: #009900;">&#40;</span>AuthScope.<span style="color: #006633;">ANY</span>, <span style="color: #000000; font-weight: bold;">new</span> UsernamePasswordCredentials<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin&quot;</span>,<span style="color: #0000ff;">&quot;admin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _generatedFilename <span style="color: #339933;">=</span> generateFilename<span style="color: #009900;">&#40;</span>_filename, savedconfiglist<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; HttpResponse response <span style="color: #339933;">=</span> httpclient.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>httpget<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; HttpEntity entity <span style="color: #339933;">=</span> response.<span style="color: #006633;">getEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #006633;">getStatusLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStatusCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; saveArmyConfig<span style="color: #009900;">&#40;</span>_generatedFilename, entity.<span style="color: #006633;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Log.<span style="color: #006633;">d</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TESTING&quot;</span>, <span style="color: #0000ff;">&quot;error receiving content&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>Kind regards,<br />
<a href="http://nl.linkedin.com/in/marcdekwant">Marc</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2011/02/24/android-read-file-from-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android XML parsing workaround</title>
		<link>http://www.olympicarts.nl/2010/12/16/android-xml-parsing-workaround/</link>
		<comments>http://www.olympicarts.nl/2010/12/16/android-xml-parsing-workaround/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 14:09:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Parsing]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=152</guid>
		<description><![CDATA[The problem I came across a problem while using XML in my android application. When trying to parse XML in android 2.2 and above, I read the qName variable and use that to do my magic. But in sdk version 7 (2.1) this poses a serious problem. A bug in the Android code, causes the [...]]]></description>
			<content:encoded><![CDATA[<h2>The problem</h2>
<p>I came across a problem while using XML in my android application. When trying to parse XML in android 2.2 and above, I read the qName variable and use that to do my magic. But in sdk version 7 (2.1) this poses a serious problem. A bug in the Android code, causes the qName to be empty and the localname to be filled with your XML element value.<br />
<span id="more-152"></span></p>
<h2>The solution</h2>
<p>I have coded a Utility that works around this minor issue. The code is as follows:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> qLocal<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> qName, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> localname<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> _retValue <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Build.<span style="color: #006633;">VERSION</span>.<span style="color: #006633;">SDK_INT</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _retValue <span style="color: #339933;">=</span> localname<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _retValue <span style="color: #339933;">=</span> qName<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _retValue<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>Call the function above in your startElement(&#8230;) and endElement(&#8230;) functions and assign the return value to a local variable and u are good to go and cross version compatible again.<br />
I Hope this helps you avoiding this annoying issue with XML parsing on Android 2.1.</p>
<p>Kind regards,</p>
<p><a href="http://nl.linkedin.com/in/marcdekwant">Marc</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2010/12/16/android-xml-parsing-workaround/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android Form Field Validation</title>
		<link>http://www.olympicarts.nl/2010/10/04/android-form-field-validation/</link>
		<comments>http://www.olympicarts.nl/2010/10/04/android-form-field-validation/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 14:23:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Interaction]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[Check]]></category>
		<category><![CDATA[Form]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=138</guid>
		<description><![CDATA[A simple method for the validation of your Form values in Android.]]></description>
			<content:encoded><![CDATA[<h2>Validation ??</h2>
<p>After coding a while for the Android platform, I was getting annoyed that there was no default validation support (i.e that I could find) for the validation of EditText, CheckBox etc fields.<br />
Therefore I have written a small set of interfaces/Classes that gives you and me the possibility to do the validation you need.<br />
<span id="more-138"></span></p>
<h2>The basics</h2>
<p>To be able to use the validation you need to implement de Validator Interface and extend the AbstractValidator class. In the abstract class a couple of handy methods are already implemented, but may be overridden for your specific usage.<br />
An example of an implemented validator:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.android.validator</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.CheckBox</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* A Checkbox required field<br />
&nbsp;* implementation of the validator.<br />
&nbsp;* With this validator a checkbox can be tested<br />
&nbsp;* for the required option.<br />
&nbsp;*<br />
&nbsp;* @author http://nl.linkedin.com/in/marcdekwant<br />
&nbsp;*<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CheckBoxRequiredValidator <span style="color: #000000; font-weight: bold;">extends</span> AbstractValidator <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">private</span> CheckBox _source<span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** CONSTRUCTORS */</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> CheckBoxRequiredValidator<span style="color: #009900;">&#40;</span>CheckBox source<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; _source <span style="color: #339933;">=</span> source<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> CheckBoxRequiredValidator<span style="color: #009900;">&#40;</span>CheckBox source, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> requiredMessage<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; _source <span style="color: #339933;">=</span> source<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; _requiredMessage <span style="color: #339933;">=</span> requiredMessage<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> ValidationResult validate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; ValidationResult _v <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_v<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_source.<span style="color: #006633;">isChecked</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _v <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ValidationResult<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _v <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ValidationResult<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span>, _requiredMessage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _v<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; @Override<br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> getSource<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> _source<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Example usage in a activity</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp;.....<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>validator<span style="color: #339933;">&gt;</span> validators <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>validator<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; .....<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> someMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validators.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CheckBoxRequiredValidator<span style="color: #009900;">&#40;</span>myCheckbox, <span style="color: #0000ff;">&quot;This checkbox is required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; .....<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> myAcceptMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List<span style="color: #339933;">&lt;</span>validationResult<span style="color: #339933;">&gt;</span> _validationResults <span style="color: #339933;">=</span> AbstractValidator.<span style="color: #006633;">validateAll</span><span style="color: #009900;">&#40;</span>validators<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_validationResults.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Validation is succesfull</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<h2>Source code</h2>
<p><a href='http://www.olympicarts.nl/wp-content/uploads/2010/10/AndroidValidation1.zip'>Android Validation zip</a></p>
<p>Kind regards,</p>
<p>Marc</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2010/10/04/android-form-field-validation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JEE Webservice basic auth security check with Glassfish</title>
		<link>http://www.olympicarts.nl/2010/07/08/jee-webservice-basic-auth-security-check-with-glassfish/</link>
		<comments>http://www.olympicarts.nl/2010/07/08/jee-webservice-basic-auth-security-check-with-glassfish/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 11:26:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Webservices]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[Basic]]></category>
		<category><![CDATA[RolesAllowed]]></category>
		<category><![CDATA[Webservice]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=128</guid>
		<description><![CDATA[@rolesAllowed custom implementation for JEE Webservices in GlassFish and others]]></description>
			<content:encoded><![CDATA[<h2>No @RolesAllowed available for Webservices</h2>
<p>The JEE specification is growing into a nice and easy to use specification. But some features, like Webservices and RolesAllowed, are not good enough yet. To be more precise. @RolesAllowed is not supported for plain Webservices (not doubling as EJB&#8217;s) until version 3.0 in the Servlet Specification.</p>
<p>After much reading on this subject, I have come to the conclusion that a pragmatic solution is required. My solution is just to inspect the principals based upon the logged in user and check myself if the user is allowed to continue. But you can also define the webservice as EJB.<br />
<span id="more-128"></span></p>
<h2>My setup</h2>
<p>Glassfish 3<br />
JEE<br />
Basic authentication configured in JEE project and glassfish server by JDBC realm means</p>
<h2>My @RolesAllowed / isUserInRole solution</h2>
<p>Off course an annotation can be constructed for the example below, but that I leave to other to implement.</p>
<h3>Check the principal yourself</h3>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> accessAllowed<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> role<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> retValue <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; Subject s<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; s <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Subject<span style="color: #009900;">&#41;</span> PolicyContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.security.auth.Subject.container&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Set<span style="color: #339933;">&lt;</span>principal<span style="color: #339933;">&gt;</span> principals <span style="color: #339933;">=</span> s.<span style="color: #006633;">getPrincipals</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aprincipal+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Principal</span></a> p <span style="color: #339933;">:</span> principals<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>p.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>role<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Access allowed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; retValue <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>PolicyContextException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Something is wrong. We do nothing by return access NOT allowed</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> retValue<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></div></div>
<h3>Define the webservice as EJB</h3>
<p>Another solution would be to define the webservice as an EJB also. I have not chosen this approach, but it is a matter of taste.</p>
<p>I hope the JEE specification will add/implement @RolesAllowed much needed feature for basic authenticated webservices, as in EJB&#8217;s, as fast as they can.</p>
<p>Kind regards,</p>
<p>Marc</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2010/07/08/jee-webservice-basic-auth-security-check-with-glassfish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex: Dynamic binding using a mapping file</title>
		<link>http://www.olympicarts.nl/2010/01/20/flex-dynamic-binding-using-a-mapping-file/</link>
		<comments>http://www.olympicarts.nl/2010/01/20/flex-dynamic-binding-using-a-mapping-file/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 08:08:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flex 3.0]]></category>
		<category><![CDATA[bidirectioneel]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[BindUtils]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[mapping]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=111</guid>
		<description><![CDATA[Introduction Binding can be an time consuming task in Flex. If you have a domain model and the DTO&#8217;s for your components, you need an easy way to bind the two together. Here you have two options. The first is to write alot of BindingUtils statements in either models. And finally you can write a [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>Binding can be an time consuming task in Flex. If you have a domain model and the DTO&#8217;s for your components, you need an easy way to bind the two together. Here you have two options. The first is to write alot of BindingUtils statements in either models. And finally you can write a mapping file in xml, create a custom binder class which uses the mapping file and bind the two models together.</p>
<p>I have chosen the last option, because this gives me some more flexibility handling the bindings.<br />
<span id="more-111"></span></p>
<h3>Requirements</h3>
<ul>
<li><a href="http://www.adobe.com/go/tryflex">Flex Builder 3</a></li>
<li>Tutorial code (See below for the files: the xml, xsd and binder.as)</li>
</ul>
<h3>Actual coding</h3>
<p>To make this idear happen, I needed several things. First, I needed my two models (the real domain model and the DTO for the view components) which needed to be bound together. Prerequisite for these models is that they have a single point of entry to be able to naviagate to all objects within the model.<br />
Secondly, a mapping file. I have created a easy to use mapping file in which I configure the binding rules.<br />
And finally, the class that does the actual binding based upon the mapping file and both models.</p>
<h3>Code samples</h3>
<p>The is not much more to say about this, so here I will show you samples of all code.</p>
<p><em><strong>Binding file</strong></em></p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapping</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.example.org/binding&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.example.org/binding assets/binding.xsd &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;binding</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;myList&quot;</span> <span style="color: #000066;">bidirectional</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sourceBinding</span> <span style="color: #000066;">topLevelObject</span>=<span style="color: #ff0000;">&quot;myDomainRoot&quot;</span> <span style="color: #000066;">object</span>=<span style="color: #ff0000;">&quot;myDomainRoot.subDomainObj&quot;</span> <span style="color: #000066;">field</span>=<span style="color: #ff0000;">&quot;myList&quot;</span> <span style="color: #000066;">isCollection</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;targets<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;targetBinding</span> <span style="color: #000066;">topLevelObject</span>=<span style="color: #ff0000;">&quot;myDTORoot&quot;</span> <span style="color: #000066;">object</span>=<span style="color: #ff0000;">&quot;customer.address&quot;</span> <span style="color: #000066;">field</span>=<span style="color: #ff0000;">&quot;myList&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;targetBinding</span> <span style="color: #000066;">topLevelObject</span>=<span style="color: #ff0000;">&quot;myDTORoot&quot;</span> <span style="color: #000066;">object</span>=<span style="color: #ff0000;">&quot;company&quot;</span> <span style="color: #000066;">field</span>=<span style="color: #ff0000;">&quot;anotherList&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/targets<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p><em><strong>XSD file</strong></em></p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;schema</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;mapping&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">&quot;http://www.example.org/binding&quot;</span> <span style="color: #000066;">xmlns:tns</span>=<span style="color: #ff0000;">&quot;http://www.example.org/binding&quot;</span> <span style="color: #000066;">elementFormDefault</span>=<span style="color: #ff0000;">&quot;qualified&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;mapping&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;choice</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">&quot;unbounded&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;binding&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sourceBinding&quot;</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;topLevelObject&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;object&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;field&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;isCollection&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;targets&quot;</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;targetBinding&quot;</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">&quot;unbounded&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;topLevelObject&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;object&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;field&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;bidirectional&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;string&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/choice<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/schema<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p><strong>Mapping explenation</strong><br />
A <strong>binding</strong> element represents a complete bi-rectional binding<br />
A <strong>sourceBinding</strong> element represents the source end object and property of the required binding. <em>TopLevelObject indicates the root of the model</em>. The object (for example rootObject.subObject) represents the navigation to the object that needs to facilitate the binding. If the topLevelObject and the first object in the property Object are the same, this is ignored in the navigation. It just means that the model has no nested objects, but only properties.<br />
A <strong>targetBinding</strong> element represents the target to be bound. Same rules as the source binding apply.</p>
<p><em><strong>Binding class</strong></em></p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">binding</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">BindingUtils</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">logging</span>.<span style="color: #006600;">ILogger</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">logging</span>.<span style="color: #0066CC;">Log</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">logging</span>.<span style="color: #006600;">LogEventLevel</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">logging</span>.<span style="color: #006600;">targets</span>.<span style="color: #006600;">TraceTarget</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* This class provides the binding capability between<br />
&nbsp; &nbsp; &nbsp;* 2 models. The binding is read from a XML file and<br />
&nbsp; &nbsp; &nbsp;* used in the binding process.<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @author http://nl.linkedin.com/in/marcdekwant<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Binder <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span> source=<span style="color: #ff0000;">'/assets/bindings.xml'</span>, mimeType=<span style="color: #ff0000;">&quot;application/octet-stream&quot;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _rawFile:<span style="color: #000000; font-weight: bold;">Class</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// The from file read xml representation of the bindingfile</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _bindings:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// The original domain model</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _model:<span style="color: #66cc66;">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// The target model (DTO's related to the UI components)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _dto:<span style="color: #66cc66;">*</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> logger:ILogger &nbsp;= &nbsp;<span style="color: #0066CC;">Log</span>.<span style="color: #006600;">getLogger</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Binder&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Constructor<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param dto the target domain model<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param model the source domain model<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Binder<span style="color: #66cc66;">&#40;</span> dto:<span style="color: #66cc66;">*</span>, model:<span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>._dto &nbsp;= &nbsp;dto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">this</span>._model &nbsp;= &nbsp;model;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> file:ByteArray &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">new</span> _rawFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> str:<span style="color: #0066CC;">String</span> &nbsp;= &nbsp;file.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span> file.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _bindings &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span> str <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initLogging<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createBindings<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Initialize the logging<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* TODO refactor to controller or application level<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initLogging<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> logTarget:TraceTarget &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">new</span> TraceTarget<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span style="color: #0066CC;">level</span> &nbsp;= &nbsp;LogEventLevel.<span style="color: #006600;">ALL</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span style="color: #006600;">filters</span> &nbsp;= &nbsp;<span style="color: #66cc66;">&#91;</span> <span style="color: #ff0000;">&quot;*&quot;</span>, <span style="color: #ff0000;">&quot;nl.dialoog.binding.*&quot;</span> <span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span style="color: #006600;">includeCategory</span> &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span style="color: #006600;">includeDate</span> &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span style="color: #006600;">includeLevel</span> &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span style="color: #006600;">includeTime</span> &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">Log</span>.<span style="color: #006600;">addTarget</span><span style="color: #66cc66;">&#40;</span> logTarget <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* This method retrieves a property from a<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* given object. THis method gives the binding<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* class the capability to chain objects.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param _objTarget The object<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param _innerObj the property of the targetObject<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return the innerObj from the targetobj<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> resolveNestedObject<span style="color: #66cc66;">&#40;</span> _objTarget:<span style="color: #66cc66;">*</span>, _innerObj:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _objTarget<span style="color: #66cc66;">&#91;</span> _innerObj <span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* This method resolves the property from an object chain to<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* be bound to another property from an object chain.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param _obj The baseObject (domain model root, or DTO root)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param _xmlObj the target to be found in the root<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return the target object to be bound.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> resolveSourceObject<span style="color: #66cc66;">&#40;</span> _obj:<span style="color: #66cc66;">*</span>, _xmlObj:<span style="color: #0066CC;">XML</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> _objArray:<span style="color: #0066CC;">Array</span> &nbsp;= &nbsp;_xmlObj.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">object</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;.&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> &nbsp;= &nbsp;<span style="color: #cc66cc;">0</span>; i <span style="color: #66cc66;">&lt;</span> _objArray.<span style="color: #0066CC;">length</span>; i++ <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> _xmlObj.<span style="color: #66cc66;">@</span>topLevelObject <span style="color: #66cc66;">!</span>= _xmlObj.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">object</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _obj &nbsp;= &nbsp;resolveNestedObject<span style="color: #66cc66;">&#40;</span> _obj, _objArray<span style="color: #66cc66;">&#91;</span> i <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _obj;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp;Actual method that hold the logic in creating bindings<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp;based upon the binding xml file.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createBindings<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Start create bindings...&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> _objSource:<span style="color: #66cc66;">*</span> &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> _objTarget:<span style="color: #66cc66;">*</span> &nbsp;= &nbsp;<span style="color: #000000; font-weight: bold;">null</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Set the default namespace from the binding.xml, in order to process the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// mapping file. &quot;&quot; relates to the xmlns=&quot;&quot; attribute in the root element</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">default</span> <span style="color: #0066CC;">xml</span> namespace = _bindings.<span style="color: #006600;">namespace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// traverse over all &lt;binding&gt; elements</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> xmlBinding:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> _bindings.<span style="color: #006600;">binding</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Create binding for &quot;</span> + xmlBinding.<span style="color: #66cc66;">@</span>id + <span style="color: #ff0000;">&quot; bi-directional:&quot;</span> + xmlBinding.<span style="color: #66cc66;">@</span>bidirectional <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> sourceBinding:<span style="color: #0066CC;">XML</span> &nbsp;= &nbsp;xmlBinding.<span style="color: #006600;">sourceBinding</span><span style="color: #66cc66;">&#91;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _objSource &nbsp;= &nbsp;resolveSourceObject<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span>._model, sourceBinding <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Collection binding...&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// traverse over all &lt;targetBinding&gt; elements</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> xmlTargetBinding:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> xmlBinding.<span style="color: #006600;">targets</span>.<span style="color: #006600;">targetBinding</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Construction of bindings from &quot;</span> + sourceBinding.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">object</span> + <span style="color: #ff0000;">&quot;.&quot;</span> + sourceBinding.<span style="color: #66cc66;">@</span>field + <span style="color: #ff0000;">&quot; to &quot;</span> + xmlTargetBinding.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">object</span> + <span style="color: #ff0000;">&quot;.&quot;</span> + xmlTargetBinding.<span style="color: #66cc66;">@</span>field <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _objTarget &nbsp;= &nbsp;resolveSourceObject<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span>._dto, xmlTargetBinding <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// A collection requires a slightly different binding then properties</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// because the ArrayCollection contains binding mechanism in its own class.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> sourceBinding.<span style="color: #66cc66;">@</span>isCollection == <span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Collection binding...&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _objTarget<span style="color: #66cc66;">&#91;</span> xmlTargetBinding.<span style="color: #66cc66;">@</span>field <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span> <span style="color: #ff0000;">&quot;source&quot;</span> <span style="color: #66cc66;">&#93;</span> &nbsp;= &nbsp;_objSource<span style="color: #66cc66;">&#91;</span> sourceBinding.<span style="color: #66cc66;">@</span>field <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span> <span style="color: #ff0000;">&quot;source&quot;</span> <span style="color: #66cc66;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;Property binding...&quot;</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> _sourceStr:<span style="color: #0066CC;">String</span> &nbsp;= &nbsp;sourceBinding.<span style="color: #66cc66;">@</span>field;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> _targetStr:<span style="color: #0066CC;">String</span> &nbsp;= &nbsp;xmlTargetBinding.<span style="color: #66cc66;">@</span>field;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BindingUtils.<span style="color: #006600;">bindProperty</span><span style="color: #66cc66;">&#40;</span> _objSource, _sourceStr, _objTarget, _targetStr <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BindingUtils.<span style="color: #006600;">bindProperty</span><span style="color: #66cc66;">&#40;</span> _objTarget, _targetStr, _objSource, _sourceStr <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Bindings created...&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p><strong><em>Sample Application file</em></strong></p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span></span><br />
<span style="color: #009900;">&nbsp; <span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;onCreationComplete();&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;![CDATA[</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; import mx.binding.utils.BindingUtils;</span><br />
<br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Bindable]</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private var myDomainRoot:MyDomainRoot;</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Bindable]</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private var myDTORoot:MyDTORoot;</span><br />
<br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; private function onCreationComplete():void {</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDomainRoot= new MyDomainRoot();</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDTORoot = new MyDTORoot();</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var _binder:Binder = new Binder(myDTORoot,myDomainRoot);</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; ]]&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Kind regards,</p>
<p><a href="http://nl.linkedin.com/in/marcdekwant">Marc de Kwant</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2010/01/20/flex-dynamic-binding-using-a-mapping-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex 3 Custom validation of grouped input fields</title>
		<link>http://www.olympicarts.nl/2009/12/01/flex-3-custom-validation-of-grouped-input-fields/</link>
		<comments>http://www.olympicarts.nl/2009/12/01/flex-3-custom-validation-of-grouped-input-fields/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 17:12:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flex 3.0]]></category>
		<category><![CDATA[Interaction]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=73</guid>
		<description><![CDATA[In this article I am going to show you a Flex 3 validation customization that enables you to validate multiple input fields with 1 validator and place the validation results in a component instead of a tooltip.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>Flex 3 has nicely build-in validation mechanism, but sometimes you wish they had not embedded this so deep into the components, that customization becomes a laborish task. I have also read many articles on customizations of this mechanism, but I have not found a working solution to my specific wish. What I want is validation of single input fields, multiple input and arbitrary placement of errors<br />
besides the tooltip method.</p>
<p><span id="more-73"></span></p>
<h3>Requirements</h3>
<ul>
<li><a href="http://www.adobe.com/go/tryflex">Flex Builder 3</a></li>
<li>Tutorial code (See step 7 for both files)</li>
</ul>
<h3>Steps</h3>
<p>Now I am going to describe the steps I took to create this validator.</p>
<h4>Step 1</h4>
<p>I have created a Flex (web) project in my workspace. In this project I have 1 mxml file (my application file). I have named this ValidationTutorial.mxml.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>In this mxml I will put 3 input field (day, month, year) in a hbox. Furthermore I will place a hidden Label<br />
below the hbox. These are my basic components that I will be using to demonstrate the multiple input validator.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;day&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;month&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;year&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;errorMsgbirthdayValidationModel&quot;</span> <span style="color: #000066;">visible</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">includeInLayout</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h4>Step 2</h4>
<p>Code our custom validator. Now we have to create the validator. file -> new -> actionscript class and call it BirthdayValidator (make it extend Validator). override the protected function doValidation, put a call to super.doValidation(value) in it and we have our foundation for the validator in place.  Your actionscript class should look as follows</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BirthdayValidator <span style="color: #0066CC;">extends</span> Validator <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BirthdayValidator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; override protected <span style="color: #000000; font-weight: bold;">function</span> doValidation<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Init the results array with the basic validation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> results:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">super</span>.<span style="color: #006600;">doValidation</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> results;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<h4>Step 3</h4>
<p>This is a relatively small step, but contains the magic that will enable me to validate and control the output regarding 3 input fields. Make a mental note of the valError element, which I will use later on.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Model</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;birthdayValidationModel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;birthday<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;day<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{day.text}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/day<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;month<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{month.text}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/month<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;year<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{year.text}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/year<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valError<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/valError<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/birthday<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h4>Step 4</h4>
<p>We define the validator and link all components together. this means we are going to tell the validator that the source for validation is our model and the results will be displayed in the label. If you now run the application, nothing will happen when tabbing across the fields. This is because we have not defined the triggers for the validator and the actual implementation of the validator. We will put this on the last input with focusOut. The implementation for the validator is for tutorial purpose simple.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:BirthdayValidator</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;birthdayVal&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;{birthdayValidationModel}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;birthday&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">listener</span>=<span style="color: #ff0000;">&quot;{errorMsgbirthdayValidationModel}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">trigger</span>=<span style="color: #ff0000;">&quot;{year}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">triggerEvent</span>=<span style="color: #ff0000;">&quot;focusOut&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<p>We are now close to a working example.</p>
<h4>Step 5</h4>
<p>Now we define the invalid handler and the valid handler. These methods will contain code to set/unset validation texts. Configure them into the validator and edit the label so that it responds to the errors in it. When you have done this, you will see validation results below the inputs when you enter no values and  focusOut on the year input (last input field).</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:BirthdayValidator</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;birthdayVal&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;{birthdayValidationModel}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;birthday&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">listener</span>=<span style="color: #ff0000;">&quot;{errorMsgbirthdayValidationModel}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">trigger</span>=<span style="color: #ff0000;">&quot;{year}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">triggerEvent</span>=<span style="color: #ff0000;">&quot;focusOut&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">invalid</span>=<span style="color: #ff0000;">&quot;onInvalidHandler(event)&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">valid</span>=<span style="color: #ff0000;">&quot;onValidHandler(event)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div>
<p>And the methods&#8230;.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Validationresult event handler. This function<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* places the validation results into the appropriate<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* label for error text placement beneath an input<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* text.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param event Results of the input box(es) validation<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> onInvalidHandler<span style="color: #66cc66;">&#40;</span> event:ValidationResultEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> _error:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> validator:Validator = event.<span style="color: #0066CC;">target</span> as Validator;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">var</span> result:ValidationResult <span style="color: #b1b100;">in</span> event.<span style="color: #006600;">results</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _error+=result.<span style="color: #006600;">errorCode</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// All validation results will be displayed in a label component</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> errorLabel:Label = validator.<span style="color: #006600;">listener</span> as Label;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorLabel.<span style="color: #0066CC;">text</span> = _error;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: #006600;">stopImmediatePropagation</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Validation result handler. This function removes all<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* error texts from the error label for the current input<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* component.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param event Results of the input box(es) validation<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> onValidHandler<span style="color: #66cc66;">&#40;</span> event:ValidationResultEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> _error:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> validator:Validator = event.<span style="color: #0066CC;">target</span> as Validator;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// All validation results will be displayed in a label component</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> errorLabel:Label = validator.<span style="color: #006600;">listener</span> as Label;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorLabel.<span style="color: #0066CC;">text</span> = _error;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span style="color: #006600;">stopImmediatePropagation</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div></div>
<h4>Step 6</h4>
<p>Add styling. Just some nice sugar, but styling is everything. Add this styling to your ValidationTutorial.mxml <example> And add the following method to the script to use this styling.<br />
Add to the 3 input field the following property</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">styleName=<span style="color: #ff0000;">&quot;{ValidatorUtil.showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.day)}&quot;</span></div></div>
<h4>Step 7</h4>
<p>Now comes the 4th element in the mx:model into focus. When you run the application you will see deep blue borders, but they do not change to red borders were there is an error detected by the validation. For this to work we need to programaticly fill the error element to reflect the inputs that are invalid.<br />
This we will do in the validator and a helper method in our ValidationTutorial.mxml</p>
<p>The BirthdayValidator</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">validators</span>.<span style="color: #006600;">ValidationResult</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">validators</span>.<span style="color: #006600;">Validator</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BirthdayValidator <span style="color: #0066CC;">extends</span> Validator <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ERROR_START_ELEMENT_TAG:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&lt;errorElement&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ERROR_END_ELEMENT_TAG:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&lt;/errorElement&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ERROR_DAY_TAG:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&lt;error&gt;day&lt;/error&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ERROR_MONTH_TAG:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&lt;error&gt;month&lt;/error&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const ERROR_YEAR_TAG:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&lt;error&gt;year&lt;/error&gt;&quot;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BirthdayValidator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; override protected <span style="color: #000000; font-weight: bold;">function</span> doValidation<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> day:<span style="color: #0066CC;">String</span> = value.<span style="color: #006600;">day</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> month:<span style="color: #0066CC;">String</span> = value.<span style="color: #006600;">month</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> year:<span style="color: #0066CC;">String</span> = value.<span style="color: #006600;">year</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> errorString:<span style="color: #0066CC;">String</span> = ERROR_START_ELEMENT_TAG;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Init the results array with the basic validation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> results:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">super</span>.<span style="color: #006600;">doValidation</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>day == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">||</span> day == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Texts and codes need to be refactered out of this util</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// into a text file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ValidationResult<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;day&quot;</span>, <span style="color: #ff0000;">&quot;noDay&quot;</span>, <span style="color: #ff0000;">&quot; No day&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorString += ERROR_DAY_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Check month field.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>month == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">||</span> month == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Texts and codes need to be refactered out of this util</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// into a text file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;results.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ValidationResult<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;month&quot;</span>, <span style="color: #ff0000;">&quot;noMonth&quot;</span>, <span style="color: #ff0000;">&quot; No month&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorString += ERROR_MONTH_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Check month field.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>year == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">||</span> year == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// Texts and codes need to be refactered out of this util</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// into a text file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ValidationResult<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;year&quot;</span>, <span style="color: #ff0000;">&quot;noYear&quot;</span>, <span style="color: #ff0000;">&quot; No year&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorString += ERROR_YEAR_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorString += ERROR_END_ELEMENT_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value.<span style="color: #006600;">valError</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span>errorString<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> results;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>The ValidatorTutorial.mxml</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;vertical&quot;</span> <span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; &nbsp; .errorBorderStyle {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-color: red;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-style: solid;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-bottom: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-left: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-right: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-top: 2px;<br />
<br />
&nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; .defaultBorderStyle {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-color: blue;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-style: solid;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-bottom: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-left: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-right: 2px;<br />
&nbsp; &nbsp; &nbsp; &nbsp; border-thickness-top: 2px;<br />
<br />
&nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;![CDATA[</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; import mx.core.UIComponent;</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; import mx.validators.ValidationResult;</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; import mx.validators.Validator;</span><br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; import mx.events.ValidationResultEvent;</span><br />
<br />
<span style="color: #339933;">&nbsp; &nbsp; &nbsp; &nbsp; /**</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * Validationresult event handler. This function</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * places the validation results into the appropriate</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * label for error text placement beneath an input</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * text.</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; *</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * @param event Results of the input box(es) validation</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;public static function onInvalidHandler( event:ValidationResultEvent ):void {</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var _error:String = &quot;&quot;;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var validator:Validator = event.target as Validator;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for each ( var result:ValidationResult in event.results ) {</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_error+=result.errorCode;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// All validation results will be displayed in a label component</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var errorLabel:Label = validator.listener as Label;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorLabel.text = _error;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event.stopImmediatePropagation();</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; /**</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * Validation result handler. This function removes all</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * error texts from the error label for the current input</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * component.</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; *</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * @param event Results of the input box(es) validation</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;public static function onValidHandler( event:ValidationResultEvent ):void {</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var _error:String = &quot;&quot;;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var validator:Validator = event.target as Validator;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// All validation results will be displayed in a label component</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var errorLabel:Label = validator.listener as Label;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorLabel.text = _error;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event.stopImmediatePropagation();</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;/**</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * Function reserved for complex objects. In this we mean mx:model</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * type objects for multi input validations. (dates where day,month,year</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * are seperated input controls).</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; *</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * @param errors A xmllist of elements containing the controls that need</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp;or do not need error styling.</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * @param input the control we like to style.</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; * @return &nbsp;the new styling information.</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;public static function showErrorBorder( errors:XML, input:UIComponent ):String {</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var styleName:String &nbsp;= &nbsp;&quot;defaultBorderStyle&quot;;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Check for not null, otherwise the flashplayer</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// will silently ignore the nullpointer and break off</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// any further styling for the target control</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( errors != null &amp;&amp; errors.error != null ) {</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for each ( var error:XML in errors.error ) {</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( error == input.id ) {</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;styleName &nbsp;= &nbsp;&quot;errorBorderStyle&quot;;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return styleName;</span><br />
<span style="color: #339933;"> &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<br />
<span style="color: #339933;">&nbsp; &nbsp; ]]&gt;</span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Model</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;birthdayValidationModel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;birthday<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;day<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{day.text}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/day<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;month<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{month.text}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/month<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;year<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{year.text}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/year<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valError<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/valError<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/birthday<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;day&quot;</span> <span style="color: #000066;">styleName</span>=<span style="color: #ff0000;">&quot;{showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.day)}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;month&quot;</span> <span style="color: #000066;">styleName</span>=<span style="color: #ff0000;">&quot;{showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.month)}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;year&quot;</span> <span style="color: #000066;">styleName</span>=<span style="color: #ff0000;">&quot;{showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.year)}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:HBox<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Label</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;errorMsgbirthdayValidationModel&quot;</span> <span style="color: #000066;">visible</span>=<span style="color: #ff0000;">&quot;{errorMsgbirthdayValidationModel.text!=''}&quot;</span> <span style="color: #000066;">includeInLayout</span>=<span style="color: #ff0000;">&quot;{errorMsgbirthdayValidationModel.text!=''}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:BirthdayValidator</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;birthdayVal&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">source</span>=<span style="color: #ff0000;">&quot;{birthdayValidationModel}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;birthday&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">listener</span>=<span style="color: #ff0000;">&quot;{errorMsgbirthdayValidationModel}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">trigger</span>=<span style="color: #ff0000;">&quot;{year}&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">triggerEvent</span>=<span style="color: #ff0000;">&quot;focusOut&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">invalid</span>=<span style="color: #ff0000;">&quot;onInvalidHandler(event)&quot;</span></span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">valid</span>=<span style="color: #ff0000;">&quot;onValidHandler(event)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<h4>Final note</h4>
<p>And now the magic is complete. You have build a multiple input validator, with error message customization and placement. You can add many enhancement, that I will leave up to your imagination.</p>
<p>I hope you enjoy coding Flex/ActionScript as I do.</p>
<p>Kind regards,</p>
<p><a href="http://nl.linkedin.com/in/marcdekwant">Marc de Kwant</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2009/12/01/flex-3-custom-validation-of-grouped-input-fields/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How To: Load a spring application from a jar file</title>
		<link>http://www.olympicarts.nl/2009/08/24/how-to-load-a-spring-application-from-a-jar-file/</link>
		<comments>http://www.olympicarts.nl/2009/08/24/how-to-load-a-spring-application-from-a-jar-file/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 07:18:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[classpath loading]]></category>
		<category><![CDATA[Context]]></category>
		<category><![CDATA[Import-tag]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=63</guid>
		<description><![CDATA[Consider the following situation: Loading 3 application context files in a Swing application. 2 of the context files are in jar-files. All context files depend on the component-scan option. The Application context gets loaded from my Swing app. The method I use, is the import resource option in the context file. Read on how to [...]]]></description>
			<content:encoded><![CDATA[<p>Consider the following situation:</p>
<p>Loading 3 application context files in a Swing application. 2 of the context files are in jar-files.<br />
All context files depend on the component-scan option. The Application context gets loaded from my Swing app.<br />
The method I use, is the import resource option in the context file. Read on how to configure this in your application context.<br />
<span id="more-63"></span></p>
<p>My DAO class</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.foo.bar.dao</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.stereotype.Repository</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nl.foo.bar.domain.GOClass</span><span style="color: #339933;">;</span><br />
<br />
@<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arepository+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Repository</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;goClassDAO&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GOClassDAOJPA <span style="color: #000000; font-weight: bold;">extends</span> BaseDAOJPA<span style="color: #339933;">&lt;</span>goclass<span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">implements</span> GOClassDAO <span style="color: #009900;">&#123;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>ApplicationContext-dao.xml</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:component-scan</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;nl.foo.bar.dao&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:include-filter</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;annotation&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;org.springframework.stereotype.Repository&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context:component-scan<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>ApplicationContext-controller.xml (this gets loaded from my swing application)</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;import</span> <span style="color: #000066;">resource</span>=<span style="color: #ff0000;">&quot;classpath:ApplicationContext-dao.xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:annotation-config</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:component-scan</span> <span style="color: #000066;">base-package</span>=<span style="color: #ff0000;">&quot;nl.foo.bar.gui.controller&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:include-filter</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;annotation&quot;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;org.springframework.stereotype.Controller&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context:component-scan<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Code snippet from my swing application</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> locations <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;ApplicationContext-controller.xml&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; ClassPathXmlApplicationContext ctx <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClassPathXmlApplicationContext<span style="color: #009900;">&#40;</span>locations<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; ApplicationController appController <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ApplicationController<span style="color: #009900;">&#41;</span>ctx.<span style="color: #006633;">getBean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;applicationController&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I have tried various other options in the past (like adding &#8220;classpath:*/ApplicationContext-dao.xml&#8221; and variations to the locations) too no success.</p>
<p>The way to go is the <strong>import-tag</strong> in my opinion. Works like a charm.</p>
<p>Kind regards,<br />
<a href="http://www.linkedin.com/in/marcdekwant">Marc de Kwant</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2009/08/24/how-to-load-a-spring-application-from-a-jar-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webservices with Spring and Castor</title>
		<link>http://www.olympicarts.nl/2009/08/17/webservices-with-spring-and-castor/</link>
		<comments>http://www.olympicarts.nl/2009/08/17/webservices-with-spring-and-castor/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 09:33:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Castor]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[Spring-WS]]></category>
		<category><![CDATA[Webservices]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=24</guid>
		<description><![CDATA[Today, webservices are used primarily to expose some services of an application to the outside world. There are a lot of tools available to consume webservices. Tools like Mule, Axis and Spring. This article describes a method of exposing Java services as webservices. The technique&#8217;s / tools used to accomplice this are; Java, Spring and [...]]]></description>
			<content:encoded><![CDATA[<p>Today, webservices are used primarily to expose some services of an application to the outside world. There are a lot of tools available to consume webservices. Tools like Mule, Axis and Spring.<br />
This article describes a method of exposing Java services as webservices. The technique&#8217;s / tools used to accomplice this are; Java, Spring and Castor.<br />
There are many other tools available, like Axis, to expose java services as webservices. The reason I used Spring and Castor is the simplicity in creating webservices. Spring takes care of all boilerplate coding and Castor&#8217;s mapping capability takes care of the Object &lt;-&gt; XML mapping without the need to generate any java objects the way Axis does. This way you have clean java code, supported with configuration in Spring and a clean Castor mapping to expose your service as a webservice.<br />
<span id="more-24"></span></p>
<h2>Knowledge</h2>
<p>I presume that you posses the following knowledge</p>
<ul>
<li>Java web component developer knowledge level</li>
<li>Know how to use Eclipse and the svn and/or Maven plugin</li>
<li>Basic understanding of Spring</li>
<li>Basic understanding of Maven (but you do not need knowledge besides being able to install the tooling)</li>
<li>Basic understanding of webservices</li>
<li>Basic understanding of Tomcat</li>
</ul>
<h2>Requirements</h2>
<p>To be able to run the provided example code you need the following applications and tools.</p>
<ul>
<li><a href="http://maven.apache.org/download.html">Maven 2.X</a></li>
<li><a href="http://www.eclipse.org/mylyn/downloads/">Eclipse Mylin</a> or <a href="http://www.springsource.com/products/sts">SpringSource Toolsuite</a></li>
<li><a href="http://blog.springsource.com/2008/12/05/spring-framework-30-m1-released/">Spring 3.0.0</a> M3 or higher</li>
<li><a href="http://www.castor.org/">Castor 1.2</a></li>
<li><a href="http://tomcat.apache.org/download-60.cgi">Tomcat 6</a></li>
</ul>
<p>For a complete overview of the required libraries, you can view the pom.xml in the example code. There is <strong>NO</strong> need o download the tooling yourself, this will be done by maven.</p>
<h2>The example</h2>
<p>This example exposes a webservice that returns a Artist object from a (HSQL) database, given an id. The example will not explain how to create a CRUD application using DAO&#8217;s and services etc. This should be knowledge you already have. I have provided an example project, that contains the necessary CRUD code for this webservice project to use.</p>
<h2>Project configuration</h2>
<p>The next thing you need to do is to download the example projects from google code. These are the <a href="http://code.google.com/p/top2000persistence/">Top2000Persistence</a> and <a href="http://code.google.com/p/top2000webservice/">Top2000Webservices</a> project.</p>
<p>First you need to checkout the persistence project. The webservice project depends on it. The persistence project is a smaple project using Spring, JPA and Hibernate.</p>
<p>The way I do this is the following:</p>
<ul>
<li>Startup your Eclipse</li>
<li>File -> new -> Other -> Maven -> Checkout maven projects&#8230;&#8230;</li>
<li>select svn from the dropdown</li>
<li>Paste the url http://top2000persistence.googlecode.com/svn/trunk/</li>
<li>click on Finish</li>
</ul>
<p>The project wil be downloaded into your Eclipse and configured as a maven/java project. Below an image showing the steps I have described here:</p>
<div id="attachment_40" class="wp-caption alignleft" style="width: 450px"><img src="http://www.olympicarts.nl/wp-content/uploads/2009/06/newmavenproject11.gif" alt="New Maven Project Dialog" title="New Maven Project Dialog" width="440" height="190" class="size-full wp-image-40" /><p class="wp-caption-text">New Maven Project Dialog</p></div>
<p>Now you can build the project either with Eclipse, Maven plugin in Eclipse or cmdline Maven command. For example, if you right-click the project -> run as -> maven test, this should be part of your output</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[INFO] Scanning for projects...<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] Building Top2000Persistence<br />
[INFO]<br />
[INFO] Id: Top2000:Top2000Persistence:jar:1.0-SNAPSHOT<br />
[INFO] task-segment: [test]<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] [resources:resources]<br />
[INFO] Using default encoding to copy filtered resources.<br />
[INFO] [compiler:compile]<br />
[INFO] Nothing to compile - all classes are up to date<br />
[INFO] [resources:testResources]<br />
[INFO] Using default encoding to copy filtered resources.<br />
[INFO] [compiler:testCompile]<br />
[INFO] Nothing to compile - all classes are up to date<br />
[INFO] [surefire:test]<br />
.....<br />
.....<br />
.....<br />
<br />
Results :<br />
<br />
Tests run: 4, Failures: 0, Errors: 0, Skipped: 1<br />
<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] BUILD SUCCESSFUL<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] Total time: 9 seconds<br />
[INFO] Finished at: Mon Jun 29 11:28:38 CEST 2009<br />
[INFO] Final Memory: 2M/9M<br />
[INFO] ------------------------------------------------------------------------</div></div>
<p>If you experience other results that the above, you might need to manaully download libraries and install then into your local maven repository.  In the section resources you will find the resource for the maven documentation and the maven install plugin documentation.</p>
<p>The same you must do for the Top2000Webservices project.<br />
The way I do this is the following:</p>
<ul>
<li>File -> new -> Other -> Maven -> Checkout maven projects&#8230;&#8230;</li>
<li>select svn from the dropdown</li>
<li>Paste the url http://top2000webservice.googlecode.com/svn/trunk/</li>
<li>click on Finish</li>
</ul>
<p>The project wil be downloaded into your Eclipse and configured as a maven/web project/java. The dependency Top2000Persistence will be included by the maven process. You should have 2 project which look something like this:</p>
<div id="attachment_49" class="wp-caption alignnone" style="width: 268px"><img src="http://www.olympicarts.nl/wp-content/uploads/2009/06/newmavenwebproject1.gif" alt="New Maven Web project" title="New Maven Web project" width="258" height="321" class="size-full wp-image-49" /><p class="wp-caption-text">New Maven Web project</p></div>
<p>You can now do right-click project -> run as -> maven test, the output should be as follows:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[INFO] Scanning for projects...<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] Building Top2000Webservices<br />
[INFO]<br />
[INFO] Id: Top2000:Top2000Webservices:war:1.0<br />
[INFO] task-segment: [test]<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] [resources:resources]<br />
[INFO] Using default encoding to copy filtered resources.<br />
<br />
......<br />
......<br />
......<br />
<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] BUILD SUCCESSFUL<br />
[INFO] ------------------------------------------------------------------------<br />
[INFO] Total time: 6 seconds<br />
[INFO] Finished at: Mon Jun 29 12:18:37 CEST 2009<br />
[INFO] Final Memory: 3M/12M<br />
[INFO] ------------------------------------------------------------------------</div></div>
<p>Now we have 2 projects in our workspace, where the web project has a dependency on the persistence project. Maven test confirms that the projects compile and run the available test without problems.</p>
<p>The next thing we need to do is configure the HSQL database location for our webservices project. The persistence project uses the HSQL database in memory type for testing purposes. For usage in other purposes you need to create a file called <strong>local.config</strong> and put a set of properties into it. Below a sample of the required properties:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ds_driverclassname &nbsp;org.hsqldb.jdbcDriver<br />
ds_url &nbsp;&lt;path-to-your-db-location&gt;/test &nbsp; &nbsp; &nbsp; &lt;-- You need to provide this<br />
ds_username sa<br />
ds_password<br />
vendor_dbplatform org.hibernate.dialect.HSQLDialect<br />
showsql false<br />
generateddl false</div></div>
<p>Make sure the <strong>local.config</strong> file is in your webapp folder. (I have provided a sample in there when you download the project. Just replace my url with your own).</p>
<p>Next thing we need to do is add a server config to our eclipse workspace. I am not going to explain in detail how to do this, since I expect you already know how. But in short terms:</p>
<ul>
<li>Download and install tomcat 6.x</li>
<li>In server view right-click &#8211;> new server &#8211;> select tomcat 6 &#8211;> point it to the home dit of tomcat</li>
<li>Add the top2000webservice project</li>
<li>Finish</li>
</ul>
<p>Now you can start the server and the Top2000webservice application should start without any problems.</p>
<h2>Resources</h2>
<p>Here are usefull resources that can help you in running and working with the example project.</p>
<ul>
<li><a href="http://maven.apache.org/guides/index.html">Maven documentation</a></li>
<li><a href="http://maven.apache.org/plugins/maven-install-plugin/">Maven install plugin documentation</a></li>
<li><a href="http://www.springsource.org/documentation">Spring documentation</a></li>
<li><a href="http://tomcat.apache.org/tomcat-5.5-doc/index.html">Tomcat documentation </a></li>
<li><a href="https://www.hibernate.org/5.html">Hibernate documentation</a> </li>
<li><a href="http://code.google.com/p/top2000persistence/">Top2000Persistence demo project</a></li>
<li><a href="http://code.google.com/p/top2000webservice/">Top2000Webservices demo project</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2009/08/17/webservices-with-spring-and-castor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy JavaScript client-side form validation</title>
		<link>http://www.olympicarts.nl/2009/06/03/easy-javascript-client-side-form-validation/</link>
		<comments>http://www.olympicarts.nl/2009/06/03/easy-javascript-client-side-form-validation/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 07:46:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://dekwant.eu/?p=7</guid>
		<description><![CDATA[When you are developing a website or an application, there will come a moment that you have to start using Javascript to validate your HTML forms. Here you have 4 options. Option one is not to validate. Although tempting, it is not the best option to use. Option two is to depend on your application [...]]]></description>
			<content:encoded><![CDATA[<p>When you are developing a website or an application, there will come a moment that you have to start using <strong>Javascript</strong> to validate your HTML forms. Here you have 4 options. Option one is not to validate. Although tempting, it is not the best option to use. Option two is to depend on your application framework and hope they have implemented <strong>client-side validation</strong> into it besides the server-side validation. Option three is to custom code some basic validation scripting yourself.<br />
This is a great way to learn more about Javascript, but also the figurative pain in the butt. Option four and final option is to grab a existing Javascript validation framework from the Net and use it. I would recommend option four which brings me to the actual goal of my post<span id="more-3"></span></p>
<p>Many <strong>Javascript validation frameworks </strong>that are available have one thing in common. You <strong>MUST code</strong> Javascript to use it. And this is just the thing you are trying to avoid. Spry is a nice example here. Very powerful framework, but you have to know about Javascript to use it. Would it not be nice that u can use a Javascript validation framework without having to know Javascript. I know some designers would love it, since they do not have to depend on other developers for the Javascript. On the other side. I as a developer can spend my time on other issues besides validation coding. That mean that I will have more time if I provide my designer with a non intrusive way to implement client-side Javascript validation.</p>
<p><span id="more-15"></span></p>
<h2>Criteria for Form validation</h2>
<p>As you can imagine I have done some coding and a basic framework has been created. I have build a client-side Javascript form validation framework that adheres to the following criteria.</p>
<ul>
<li>No Javascript coding is necessary for basic validation</li>
<li>Error messages should be displayed where you want then to</li>
<li>Language support</li>
<li>Easy extensibility for custom validation code</li>
</ul>
<p>Again it is not a all encompassing framework, but it will give you the necessary tooling to make it suit your purpose.</p>
<h2>Requirements for the Javascript Form Validation framework</h2>
<p>Let us start with what we have to add to our HTML page and form in order for this validation framework to work. Only two thing are needed to activate the framework in your HTML form.</p>
<ul>
<li>Add the Javascript file to your HTML page</li>
<li>Add <em>validation=&#8221;true&#8221;</em> to your form-tag</li>
</ul>
<p><strong>Add the Javascript file</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;fvalidation.js&quot;</span> language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></div></div>
</p>
<p><strong>Add the validation attribute in the form-tag</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>form <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;simpleform&quot;</span> validate<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;onsubmit&quot;</span><span style="color: #339933;">&gt;</span></div></div>
</p>
<p>DONE. This is all you have to code to make the Javascript validation active. But it does not validate anything yet. </p>
<h2>Form validation options</h2>
<p>Adding validation is just as easy as activating it. You have to add attributes in the input-tags to use validation. Before I show you how to do this I will sum up the validation options you have.</p>
<ul>
<li>required check</li>
<li>Zipcode NL check</li>
<li>E-mail check</li>
<li>ISO date check</li>
</ul>
<p>This is not much, but as I said I have build a basic framework which can easily be extended and augmented if necessary.<br />
Besides these validations you can also use</p>
<ul>
<li><strong><em>Masking of Text input fields</em></strong></li>
<li><strong><em>Add custom Javascript checks</em></strong></li>
</ul>
<p>Enough said. Here is some example code in which I use the options above</p>
<p><strong>Required check</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>input <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;huisnummer&quot;</span> mask<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;999&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;</span></div></div>
<p><strong>Date check</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>input <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;geboortedatum&quot;</span> check<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;date_iso&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;</span></div></div>
<p>As you can see, adding client-side form validation is a no brainer with this Framework. There are some other things you might want to know about. First, error messaging. In order to use error messaging I have provided two means to display them. The first one is <strong>global errors</strong>. This means all errors will be collected and displayed in one location of your choosing. The other option is <strong>local errors</strong>. Error will be displayed near the input tag.</p>
<h2>How does javascript form validation work? </h2>
<p>Well you have to add another attribute into the form-tag and you must add either a div-tag or span-tag(s) which act as container for the messages. For example. You want to display all errors in one place. This is how you have to do it:</p>
<p>Put the messages attribute into your formtag</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">messages<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;global&quot;</span></div></div>
</p>
<p>and Put a message container in your code like this:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;global&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;globalError&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></div>
</p>
<p>Now your messages will all be displayed at the location of the div. If you want to display the messages locally you must do this:</p>
<p><div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">messages<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;local&quot;</span></div></div>
</p>
<p>and provide a span-tag for each input-tag you have validation on:</p>
<p><div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;naam_error&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;localError&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;</span></div></div>
</p>
<p>Now the errors corresponding to the <em>naam</em> input field will be displayed in the span <em>naam_error</em>. As you can see the span-id must contain the name of the input field. The framework will use this to find and disply the errors in the correct span.</p>
<h2>Custom javascript form validation</h2>
<p>I am fully aware of the fact that I have not provided a all encompassing validation library. Thus I have provided the means of extension.  You can add your own javascript method, which will be used in the validation framework. The only two things you have to do are:</p>
<p><strong>Add a attribute to your input-tag for the custom validation</strong></p>
<p><div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;naam&quot;</span> custom<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;exampleCustomCheck('Custom&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></div></div>
</p>
<p><strong>And build your own Javascript method</strong><br />
The method should have the signature below. When your custom validation fails you must return the error message to be displayed. Off course you can use a predefined error available in the validation library.</p>
<p><div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> exampleCustomCheck<span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span><br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">simpleform</span>.<span style="color: #660066;">naamCustom</span>.<span style="color: #660066;">value</span><span style="color: #339933;">!=</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;&lt;</span>br <span style="color: #339933;">/&gt;</span><br />
<span style="color: #000066; font-weight: bold;">return</span> message<span style="color: #339933;">;&lt;</span>br <span style="color: #339933;">/&gt;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
</p>
<h2>Masking in form validation</h2>
<p>The last item I want to show of is Masking. I love masking. It gives you a very powerful way of forcing the user to adhere to your desired input. I have implemented 2 types of masking. First there are a set of predefined masking option available. These are:</p>
<ul>
<li>date_iso</li>
<li>date_us</li>
<li>time</li>
<li>phone</li>
<li>ssn</li>
<li>visa</li>
</ul>
<p>Also I have provided the means for custom masking. This can be used in 3 ways. You can use the Char A, 9 and X to define what a user can enter in the field. A = alphanumerical, 9 = Numerical and X = all characters. Some examples:</p>
<p><div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mask<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;9999 AA&quot;</span></div></div>
<p>
This means that you can only enter 4 digits, a space will be forced and 2 letters.</p>
<p><div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mask<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;XX-XX-99&quot;</span></div></div>
<p>
This means that you can enter 2 characters, a &#8211; is forced, 2 characters, a &#8211; is forced and 2 digits.</p>
<p>I leave it up to you for the endless combinations that you can make with this.</p>
<p>This concludes my client-side Javascript validation framework. I hope you will use it to your satisfaction and keep me posted of wishes.</p>
<p><a href="http://www.dekwant.eu/download/validator-library.zip" title="Client-side Javascript validation Framework">Client-side Javascript validation Framework</a></p>
<p>Regards.</p>
<p><a href="http://www.linkedin.com/in/marcdekwant">Marc de Kwant </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.olympicarts.nl/2009/06/03/easy-javascript-client-side-form-validation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

