<?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>Java, Flex and JavaFX</title>
	<atom:link href="http://dekwant.eu/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://dekwant.eu</link>
	<description>Java, Flex and JavaFX examples</description>
	<lastBuildDate>Thu, 08 Jul 2010 11:46:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JEE Webservice basic auth security check with Glassfish</title>
		<link>http://dekwant.eu/?p=128</link>
		<comments>http://dekwant.eu/?p=128#comments</comments>
		<pubDate>Thu, 08 Jul 2010 11:26:32 +0000</pubDate>
		<dc:creator>mdekwant</dc:creator>
				<category><![CDATA[JEE]]></category>
		<category><![CDATA[Java]]></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">boolean</span> accessAllowed<span class="br0">&#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 class="kw3">String</span></a> role<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">boolean</span> retValue <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span><br />
&nbsp; &nbsp; Subject s<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">try</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; s <span class="sy0">=</span> <span class="br0">&#40;</span>Subject<span class="br0">&#41;</span> PolicyContext.<span class="me1">getContext</span><span class="br0">&#40;</span><span class="st0">&quot;javax.security.auth.Subject.container&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Set<span class="sy0">&lt;</span>Principal<span class="sy0">&gt;</span> principals <span class="sy0">=</span> s.<span class="me1">getPrincipals</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#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 class="kw3">Principal</span></a> p <span class="sy0">:</span> principals<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>p.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">equals</span><span class="br0">&#40;</span>role<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Access allowed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; retValue <span class="sy0">=</span> <span class="kw2">true</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">catch</span> <span class="br0">&#40;</span>PolicyContextException e<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">// Something is wrong. We do nothing by return access NOT allowed</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> retValue<span class="sy0">;</span><br />
&nbsp; <span class="br0">&#125;</span></div></td></tr></tbody></table></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://dekwant.eu/?feed=rss2&amp;p=128</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex: Dynamic binding using a mapping file</title>
		<link>http://dekwant.eu/?p=111</link>
		<comments>http://dekwant.eu/?p=111#comments</comments>
		<pubDate>Wed, 20 Jan 2010 08:08:01 +0000</pubDate>
		<dc:creator>mdekwant</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 mapping [...]]]></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;mapping</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.example.org/binding&quot;</span> <span class="re0">xmlns:xsi</span>=<span class="st0">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> <span class="re0">xsi:schemaLocation</span>=<span class="st0">&quot;http://www.example.org/binding assets/binding.xsd &quot;</span><span class="re2">&gt;</span></span><br />
<br />
&nbsp; <span class="sc3"><span class="re1">&lt;binding</span> <span class="re0">id</span>=<span class="st0">&quot;myList&quot;</span> <span class="re0">bidirectional</span>=<span class="st0">&quot;true&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;sourceBinding</span> <span class="re0">topLevelObject</span>=<span class="st0">&quot;myDomainRoot&quot;</span> <span class="re0">object</span>=<span class="st0">&quot;myDomainRoot.subDomainObj&quot;</span> <span class="re0">field</span>=<span class="st0">&quot;myList&quot;</span> <span class="re0">isCollection</span>=<span class="st0">&quot;true&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;targets<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;targetBinding</span> <span class="re0">topLevelObject</span>=<span class="st0">&quot;myDTORoot&quot;</span> <span class="re0">object</span>=<span class="st0">&quot;customer.address&quot;</span> <span class="re0">field</span>=<span class="st0">&quot;myList&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;targetBinding</span> <span class="re0">topLevelObject</span>=<span class="st0">&quot;myDTORoot&quot;</span> <span class="re0">object</span>=<span class="st0">&quot;company&quot;</span> <span class="re0">field</span>=<span class="st0">&quot;anotherList&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/targets<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/binding<span class="re2">&gt;</span></span></span><br />
<br />
<span class="sc3"><span class="re1">&lt;/mapping<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p><em><strong>XSD file</strong></em></p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;width:435px;height:300px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;schema</span> <span class="re0">id</span>=<span class="st0">&quot;mapping&quot;</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.w3.org/2001/XMLSchema&quot;</span> <span class="re0">targetNamespace</span>=<span class="st0">&quot;http://www.example.org/binding&quot;</span> <span class="re0">xmlns:tns</span>=<span class="st0">&quot;http://www.example.org/binding&quot;</span> <span class="re0">elementFormDefault</span>=<span class="st0">&quot;qualified&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;element</span> <span class="re0">name</span>=<span class="st0">&quot;mapping&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;choice</span> <span class="re0">minOccurs</span>=<span class="st0">&quot;1&quot;</span> <span class="re0">maxOccurs</span>=<span class="st0">&quot;unbounded&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;element</span> <span class="re0">name</span>=<span class="st0">&quot;binding&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;sequence<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;element</span> <span class="re0">name</span>=<span class="st0">&quot;sourceBinding&quot;</span> <span class="re0">minOccurs</span>=<span class="st0">&quot;1&quot;</span> <span class="re0">maxOccurs</span>=<span class="st0">&quot;1&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;topLevelObject&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;object&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;field&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;isCollection&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/element<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;element</span> <span class="re0">name</span>=<span class="st0">&quot;targets&quot;</span> <span class="re0">minOccurs</span>=<span class="st0">&quot;1&quot;</span> <span class="re0">maxOccurs</span>=<span class="st0">&quot;1&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;sequence<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;element</span> <span class="re0">name</span>=<span class="st0">&quot;targetBinding&quot;</span> <span class="re0">minOccurs</span>=<span class="st0">&quot;1&quot;</span> <span class="re0">maxOccurs</span>=<span class="st0">&quot;unbounded&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;topLevelObject&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;object&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;field&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/element<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/sequence<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/element<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/sequence<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;id&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;attribute</span> <span class="re0">name</span>=<span class="st0">&quot;bidirectional&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;string&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/element<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/choice<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/complexType<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/element<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/schema<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px;height:300px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br /></div></td><td><div class="actionscript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw3">import</span> flash.<span class="me1">utils</span>.<span class="me1">ByteArray</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">binding</span>.<span class="me1">utils</span>.<span class="me1">BindingUtils</span>;<br />
&nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">logging</span>.<span class="me1">ILogger</span>;<br />
&nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">logging</span>.<span class="kw3">Log</span>;<br />
&nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">logging</span>.<span class="me1">LogEventLevel</span>;<br />
&nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">logging</span>.<span class="me1">targets</span>.<span class="me1">TraceTarget</span>;<br />
<br />
&nbsp; &nbsp; <span class="coMULTI">/**<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 class="kw3">public</span> <span class="kw2">class</span> Binder <span class="br0">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>Embed<span class="br0">&#40;</span> source=<span class="st0">'/assets/bindings.xml'</span>, mimeType=<span class="st0">&quot;application/octet-stream&quot;</span> <span class="br0">&#41;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _rawFile:<span class="kw2">Class</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The from file read xml representation of the bindingfile</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _bindings:<span class="kw3">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The original domain model</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _model:<span class="sy0">*</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// The target model (DTO's related to the UI components)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _dto:<span class="sy0">*</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> logger:ILogger &nbsp;= &nbsp;<span class="kw3">Log</span>.<span class="me1">getLogger</span><span class="br0">&#40;</span> <span class="st0">&quot;Binder&quot;</span> <span class="br0">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<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 class="kw3">public</span> <span class="kw2">function</span> Binder<span class="br0">&#40;</span> dto:<span class="sy0">*</span>, model:<span class="sy0">*</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._dto &nbsp;= &nbsp;dto;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">this</span>._model &nbsp;= &nbsp;model;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> file:ByteArray &nbsp;= &nbsp;<span class="kw2">new</span> _rawFile<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> str:<span class="kw3">String</span> &nbsp;= &nbsp;file.<span class="me1">readUTFBytes</span><span class="br0">&#40;</span> file.<span class="kw3">length</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _bindings &nbsp;= &nbsp;<span class="kw2">new</span> <span class="kw3">XML</span><span class="br0">&#40;</span> str <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; initLogging<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createBindings<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<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 class="kw3">private</span> <span class="kw2">function</span> initLogging<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> logTarget:TraceTarget &nbsp;= &nbsp;<span class="kw2">new</span> TraceTarget<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span class="kw3">level</span> &nbsp;= &nbsp;LogEventLevel.<span class="me1">ALL</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span class="me1">filters</span> &nbsp;= &nbsp;<span class="br0">&#91;</span> <span class="st0">&quot;*&quot;</span>, <span class="st0">&quot;nl.dialoog.binding.*&quot;</span> <span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span class="me1">includeCategory</span> &nbsp;= &nbsp;<span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span class="me1">includeDate</span> &nbsp;= &nbsp;<span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span class="me1">includeLevel</span> &nbsp;= &nbsp;<span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logTarget.<span class="me1">includeTime</span> &nbsp;= &nbsp;<span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Log</span>.<span class="me1">addTarget</span><span class="br0">&#40;</span> logTarget <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<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 class="kw3">private</span> <span class="kw2">function</span> resolveNestedObject<span class="br0">&#40;</span> _objTarget:<span class="sy0">*</span>, _innerObj:<span class="kw3">String</span> <span class="br0">&#41;</span>:<span class="sy0">*</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> _objTarget<span class="br0">&#91;</span> _innerObj <span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<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 class="kw3">private</span> <span class="kw2">function</span> resolveSourceObject<span class="br0">&#40;</span> _obj:<span class="sy0">*</span>, _xmlObj:<span class="kw3">XML</span> <span class="br0">&#41;</span>:<span class="sy0">*</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _objArray:<span class="kw3">Array</span> &nbsp;= &nbsp;_xmlObj.<span class="sy0">@</span><span class="kw3">object</span>.<span class="kw3">split</span><span class="br0">&#40;</span> <span class="st0">&quot;.&quot;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span> <span class="kw2">var</span> i:<span class="kw3">int</span> &nbsp;= &nbsp;<span class="nu0">0</span>; i <span class="sy0">&lt;</span> _objArray.<span class="kw3">length</span>; i++ <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> _xmlObj.<span class="sy0">@</span>topLevelObject <span class="sy0">!</span>= _xmlObj.<span class="sy0">@</span><span class="kw3">object</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _obj &nbsp;= &nbsp;resolveNestedObject<span class="br0">&#40;</span> _obj, _objArray<span class="br0">&#91;</span> i <span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> _obj;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="coMULTI">/**<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 class="kw3">private</span> <span class="kw2">function</span> createBindings<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span> <span class="st0">&quot;Start create bindings...&quot;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _objSource:<span class="sy0">*</span> &nbsp;= &nbsp;<span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _objTarget:<span class="sy0">*</span> &nbsp;= &nbsp;<span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Set the default namespace from the binding.xml, in order to process the</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// mapping file. &quot;&quot; relates to the xmlns=&quot;&quot; attribute in the root element</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">default</span> <span class="kw3">xml</span> namespace = _bindings.<span class="me1">namespace</span><span class="br0">&#40;</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// traverse over all &lt;binding&gt; elements</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> each <span class="br0">&#40;</span> <span class="kw2">var</span> xmlBinding:<span class="kw3">XML</span> <span class="kw1">in</span> _bindings.<span class="me1">binding</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span> <span class="st0">&quot;Create binding for &quot;</span> + xmlBinding.<span class="sy0">@</span>id + <span class="st0">&quot; bi-directional:&quot;</span> + xmlBinding.<span class="sy0">@</span>bidirectional <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> sourceBinding:<span class="kw3">XML</span> &nbsp;= &nbsp;xmlBinding.<span class="me1">sourceBinding</span><span class="br0">&#91;</span> <span class="nu0">0</span> <span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _objSource &nbsp;= &nbsp;resolveSourceObject<span class="br0">&#40;</span> <span class="kw3">this</span>._model, sourceBinding <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span> <span class="st0">&quot;Collection binding...&quot;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// traverse over all &lt;targetBinding&gt; elements</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> each <span class="br0">&#40;</span> <span class="kw2">var</span> xmlTargetBinding:<span class="kw3">XML</span> <span class="kw1">in</span> xmlBinding.<span class="me1">targets</span>.<span class="me1">targetBinding</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span> <span class="st0">&quot;Construction of bindings from &quot;</span> + sourceBinding.<span class="sy0">@</span><span class="kw3">object</span> + <span class="st0">&quot;.&quot;</span> + sourceBinding.<span class="sy0">@</span>field + <span class="st0">&quot; to &quot;</span> + xmlTargetBinding.<span class="sy0">@</span><span class="kw3">object</span> + <span class="st0">&quot;.&quot;</span> + xmlTargetBinding.<span class="sy0">@</span>field <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _objTarget &nbsp;= &nbsp;resolveSourceObject<span class="br0">&#40;</span> <span class="kw3">this</span>._dto, xmlTargetBinding <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// A collection requires a slightly different binding then properties</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// because the ArrayCollection contains binding mechanism in its own class.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> sourceBinding.<span class="sy0">@</span>isCollection == <span class="st0">&quot;true&quot;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span> <span class="st0">&quot;Collection binding...&quot;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _objTarget<span class="br0">&#91;</span> xmlTargetBinding.<span class="sy0">@</span>field <span class="br0">&#93;</span><span class="br0">&#91;</span> <span class="st0">&quot;source&quot;</span> <span class="br0">&#93;</span> &nbsp;= &nbsp;_objSource<span class="br0">&#91;</span> sourceBinding.<span class="sy0">@</span>field <span class="br0">&#93;</span><span class="br0">&#91;</span> <span class="st0">&quot;source&quot;</span> <span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span> <span class="st0">&quot;Property binding...&quot;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _sourceStr:<span class="kw3">String</span> &nbsp;= &nbsp;sourceBinding.<span class="sy0">@</span>field;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _targetStr:<span class="kw3">String</span> &nbsp;= &nbsp;xmlTargetBinding.<span class="sy0">@</span>field;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BindingUtils.<span class="me1">bindProperty</span><span class="br0">&#40;</span> _objSource, _sourceStr, _objTarget, _targetStr <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BindingUtils.<span class="me1">bindProperty</span><span class="br0">&#40;</span> _objTarget, _targetStr, _objSource, _sourceStr <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logger.<span class="me1">debug</span><span class="br0">&#40;</span><span class="st0">&quot;Bindings created...&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p><strong><em>Sample Application file</em></strong></p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;width:435px;height:300px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;mx:Application</span> <span class="re0">xmlns:mx</span>=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span class="re0">layout</span>=<span class="st0">&quot;vertical&quot;</span></span><br />
<span class="sc3">&nbsp; <span class="re0">creationComplete</span>=<span class="st0">&quot;onCreationComplete();&quot;</span><span class="re2">&gt;</span></span><br />
<br />
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;mx:Script<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc2">&lt;![CDATA[</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; import mx.binding.utils.BindingUtils;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Bindable]</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private var myDomainRoot:MyDomainRoot;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Bindable]</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;private var myDTORoot:MyDTORoot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; private function onCreationComplete():void {</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDomainRoot= new MyDomainRoot();</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myDTORoot = new MyDTORoot(); &nbsp;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var _binder:Binder = new Binder(myDTORoot,myDomainRoot);</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; ]]&gt;</span><br />
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/mx:Script<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp;<br />
<span class="sc3"><span class="re1">&lt;/mx:Application<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Kind regards,</p>
<p><a href="http://nl.linkedin.com/in/marcdekwant">Marc de Kwant</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dekwant.eu/?feed=rss2&amp;p=111</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex 3 Custom validation of grouped input fields</title>
		<link>http://dekwant.eu/?p=73</link>
		<comments>http://dekwant.eu/?p=73#comments</comments>
		<pubDate>Tue, 01 Dec 2009 17:12:27 +0000</pubDate>
		<dc:creator>mdekwant</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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;mx:Application</span> <span class="re0">xmlns:mx</span>=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span class="re0">layout</span>=<span class="st0">&quot;vertical&quot;</span> <span class="re0">xmlns:local</span>=<span class="st0">&quot;*&quot;</span><span class="re2">&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/mx:Application<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;mx:Application</span> <span class="re0">xmlns:mx</span>=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span class="re0">layout</span>=<span class="st0">&quot;vertical&quot;</span> <span class="re0">xmlns:local</span>=<span class="st0">&quot;*&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;mx:HBox<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;day&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;month&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;year&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:HBox<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Label</span> <span class="re0">id</span>=<span class="st0">&quot;errorMsgbirthdayValidationModel&quot;</span> <span class="re0">visible</span>=<span class="st0">&quot;false&quot;</span> <span class="re0">includeInLayout</span>=<span class="st0">&quot;false&quot;</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/mx:Application<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript codecolorer" style="font-family:Monaco,Lucida Console,monospace">package <span class="br0">&#123;</span><br />
<br />
&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> BirthdayValidator <span class="kw3">extends</span> Validator <span class="br0">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> BirthdayValidator<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; override protected <span class="kw2">function</span> doValidation<span class="br0">&#40;</span>value:<span class="kw3">Object</span><span class="br0">&#41;</span>:<span class="kw3">Array</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Init the results array with the basic validation &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> results:<span class="kw3">Array</span> = <span class="kw3">super</span>.<span class="me1">doValidation</span><span class="br0">&#40;</span>value<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> results;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;mx:Model</span> <span class="re0">id</span>=<span class="st0">&quot;birthdayValidationModel&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;date<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;birthday<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;day<span class="re2">&gt;</span></span></span>{day.text}<span class="sc3"><span class="re1">&lt;/day<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;month<span class="re2">&gt;</span></span></span>{month.text}<span class="sc3"><span class="re1">&lt;/month<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;year<span class="re2">&gt;</span></span></span>{year.text}<span class="sc3"><span class="re1">&lt;/year<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;valError<span class="re2">&gt;</span></span><span class="re1">&lt;/valError<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/birthday<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/date<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:Model<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;local:BirthdayValidator</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">id</span>=<span class="st0">&quot;birthdayVal&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">required</span>=<span class="st0">&quot;true&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">source</span>=<span class="st0">&quot;{birthdayValidationModel}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">property</span>=<span class="st0">&quot;birthday&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">listener</span>=<span class="st0">&quot;{errorMsgbirthdayValidationModel}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">trigger</span>=<span class="st0">&quot;{year}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">triggerEvent</span>=<span class="st0">&quot;focusOut&quot;</span><span class="re2">/&gt;</span></span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;local:BirthdayValidator</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">id</span>=<span class="st0">&quot;birthdayVal&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">required</span>=<span class="st0">&quot;true&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">source</span>=<span class="st0">&quot;{birthdayValidationModel}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">property</span>=<span class="st0">&quot;birthday&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">listener</span>=<span class="st0">&quot;{errorMsgbirthdayValidationModel}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">trigger</span>=<span class="st0">&quot;{year}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">triggerEvent</span>=<span class="st0">&quot;focusOut&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">invalid</span>=<span class="st0">&quot;onInvalidHandler(event)&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">valid</span>=<span class="st0">&quot;onValidHandler(event)&quot;</span><span class="re2">/&gt;</span></span></div></td></tr></tbody></table></div>
<p>And the methods&#8230;.</p>
<div class="codecolorer-container actionscript mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="actionscript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="coMULTI">/**<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 class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">function</span> onInvalidHandler<span class="br0">&#40;</span> event:ValidationResultEvent <span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _error:<span class="kw3">String</span> = <span class="st0">&quot;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> validator:Validator = event.<span class="kw3">target</span> as Validator;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> each <span class="br0">&#40;</span> <span class="kw2">var</span> result:ValidationResult <span class="kw1">in</span> event.<span class="me1">results</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _error+=result.<span class="me1">errorCode</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// All validation results will be displayed in a label component</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> errorLabel:Label = validator.<span class="me1">listener</span> as Label;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorLabel.<span class="kw3">text</span> = _error;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span class="me1">stopImmediatePropagation</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="coMULTI">/**<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 class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">function</span> onValidHandler<span class="br0">&#40;</span> event:ValidationResultEvent <span class="br0">&#41;</span>:<span class="kw3">void</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> _error:<span class="kw3">String</span> = <span class="st0">&quot;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> validator:Validator = event.<span class="kw3">target</span> as Validator;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// All validation results will be displayed in a label component</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> errorLabel:Label = validator.<span class="me1">listener</span> as Label;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorLabel.<span class="kw3">text</span> = _error;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.<span class="me1">stopImmediatePropagation</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="actionscript codecolorer" style="font-family:Monaco,Lucida Console,monospace">styleName=<span class="st0">&quot;{ValidatorUtil.showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.day)}&quot;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br /></div></td><td><div class="actionscript codecolorer" style="font-family:Monaco,Lucida Console,monospace">package <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">validators</span>.<span class="me1">ValidationResult</span>;<br />
&nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">validators</span>.<span class="me1">Validator</span>;<br />
<br />
&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">class</span> BirthdayValidator <span class="kw3">extends</span> Validator <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> const ERROR_START_ELEMENT_TAG:<span class="kw3">String</span> = <span class="st0">&quot;&lt;errorElement&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> const ERROR_END_ELEMENT_TAG:<span class="kw3">String</span> = <span class="st0">&quot;&lt;/errorElement&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> const ERROR_DAY_TAG:<span class="kw3">String</span> = <span class="st0">&quot;&lt;error&gt;day&lt;/error&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> const ERROR_MONTH_TAG:<span class="kw3">String</span> = <span class="st0">&quot;&lt;error&gt;month&lt;/error&gt;&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> const ERROR_YEAR_TAG:<span class="kw3">String</span> = <span class="st0">&quot;&lt;error&gt;year&lt;/error&gt;&quot;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> BirthdayValidator<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">super</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; override protected <span class="kw2">function</span> doValidation<span class="br0">&#40;</span>value:<span class="kw3">Object</span><span class="br0">&#41;</span>:<span class="kw3">Array</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> day:<span class="kw3">String</span> = value.<span class="me1">day</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> month:<span class="kw3">String</span> = value.<span class="me1">month</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> year:<span class="kw3">String</span> = value.<span class="me1">year</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> errorString:<span class="kw3">String</span> = ERROR_START_ELEMENT_TAG;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Init the results array with the basic validation &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> results:<span class="kw3">Array</span> = <span class="kw3">super</span>.<span class="me1">doValidation</span><span class="br0">&#40;</span>value<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>day == <span class="st0">&quot;&quot;</span> <span class="sy0">||</span> day == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Texts and codes need to be refactered out of this util</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// into a text file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw2">new</span> ValidationResult<span class="br0">&#40;</span><span class="kw2">true</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;day&quot;</span>, <span class="st0">&quot;noDay&quot;</span>, <span class="st0">&quot; No day&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorString += ERROR_DAY_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Check month field. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>month == <span class="st0">&quot;&quot;</span> <span class="sy0">||</span> month == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Texts and codes need to be refactered out of this util</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// into a text file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;results.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw2">new</span> ValidationResult<span class="br0">&#40;</span><span class="kw2">true</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;month&quot;</span>, <span class="st0">&quot;noMonth&quot;</span>, <span class="st0">&quot; No month&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorString += ERROR_MONTH_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Check month field. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>year == <span class="st0">&quot;&quot;</span> <span class="sy0">||</span> year == <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Texts and codes need to be refactered out of this util</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// into a text file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results.<span class="kw3">push</span><span class="br0">&#40;</span><span class="kw2">new</span> ValidationResult<span class="br0">&#40;</span><span class="kw2">true</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;year&quot;</span>, <span class="st0">&quot;noYear&quot;</span>, <span class="st0">&quot; No year&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorString += ERROR_YEAR_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errorString += ERROR_END_ELEMENT_TAG;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value.<span class="me1">valError</span> = <span class="kw2">new</span> <span class="kw3">XML</span><span class="br0">&#40;</span>errorString<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> results;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>The ValidatorTutorial.mxml</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;mx:Application</span> <span class="re0">xmlns:mx</span>=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span class="re0">layout</span>=<span class="st0">&quot;vertical&quot;</span> <span class="re0">xmlns:local</span>=<span class="st0">&quot;*&quot;</span><span class="re2">&gt;</span></span><br />
<br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Style<span class="re2">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; &nbsp; .errorBorderStyle {<br />
&nbsp; &nbsp; &nbsp; &nbsp; <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 />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; .defaultBorderStyle {<br />
&nbsp; &nbsp; &nbsp; &nbsp; <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 />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; } <br />
<br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/mx:Style<span class="re2">&gt;</span></span></span><br />
<br />
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Script<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc2">&lt;![CDATA[</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; import mx.core.UIComponent;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; import mx.validators.ValidationResult;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; import mx.validators.Validator;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; import mx.events.ValidationResultEvent;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; /**</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * Validationresult event handler. This function</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * places the validation results into the appropriate</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * label for error text placement beneath an input </span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * text.</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * </span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * @param event Results of the input box(es) validation</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;public static function onInvalidHandler( event:ValidationResultEvent ):void {</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var _error:String = &quot;&quot;;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var validator:Validator = event.target as Validator;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for each ( var result:ValidationResult in event.results ) {</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_error+=result.errorCode;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// All validation results will be displayed in a label component</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var errorLabel:Label = validator.listener as Label;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorLabel.text = _error;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event.stopImmediatePropagation();</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; /**</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * Validation result handler. This function removes all</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * error texts from the error label for the current input </span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * component. </span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * </span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * @param event Results of the input box(es) validation</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;public static function onValidHandler( event:ValidationResultEvent ):void {</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var _error:String = &quot;&quot;;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var validator:Validator = event.target as Validator;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// All validation results will be displayed in a label component</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var errorLabel:Label = validator.listener as Label;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;errorLabel.text = _error;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event.stopImmediatePropagation();</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;/**</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * Function reserved for complex objects. In this we mean mx:model</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * type objects for multi input validations. (dates where day,month,year</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * are seperated input controls).</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * </span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * @param errors A xmllist of elements containing the controls that need</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp;or do not need error styling.</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * @param input the control we like to style.</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; * @return &nbsp;the new styling information.</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;public static function showErrorBorder( errors:XML, input:UIComponent ):String {</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var styleName:String &nbsp;= &nbsp;&quot;defaultBorderStyle&quot;;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Check for not null, otherwise the flashplayer</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// will silently ignore the nullpointer and break off</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// any further styling for the target control</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( errors != null &amp;&amp; errors.error != null ) {</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for each ( var error:XML in errors.error ) {</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( error == input.id ) {</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;styleName &nbsp;= &nbsp;&quot;errorBorderStyle&quot;;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return styleName;</span><br />
<span class="sc2"> &nbsp; &nbsp; &nbsp; &nbsp;}</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; ]]&gt;</span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:Script<span class="re2">&gt;</span></span></span><br />
<br />
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Model</span> <span class="re0">id</span>=<span class="st0">&quot;birthdayValidationModel&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;date<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;birthday<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;day<span class="re2">&gt;</span></span></span>{day.text}<span class="sc3"><span class="re1">&lt;/day<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;month<span class="re2">&gt;</span></span></span>{month.text}<span class="sc3"><span class="re1">&lt;/month<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;year<span class="re2">&gt;</span></span></span>{year.text}<span class="sc3"><span class="re1">&lt;/year<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;valError<span class="re2">&gt;</span></span><span class="re1">&lt;/valError<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/birthday<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;/date<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:Model<span class="re2">&gt;</span></span></span><br />
<br />
&nbsp; <span class="sc3"><span class="re1">&lt;mx:HBox<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;day&quot;</span> <span class="re0">styleName</span>=<span class="st0">&quot;{showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.day)}&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;month&quot;</span> <span class="re0">styleName</span>=<span class="st0">&quot;{showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.month)}&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:TextInput</span> <span class="re0">id</span>=<span class="st0">&quot;year&quot;</span> <span class="re0">styleName</span>=<span class="st0">&quot;{showErrorBorder((birthdayValidationModel.birthday.valError as XML), this.year)}&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;/mx:HBox<span class="re2">&gt;</span></span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;mx:Label</span> <span class="re0">id</span>=<span class="st0">&quot;errorMsgbirthdayValidationModel&quot;</span> <span class="re0">visible</span>=<span class="st0">&quot;{errorMsgbirthdayValidationModel.text!=''}&quot;</span> <span class="re0">includeInLayout</span>=<span class="st0">&quot;{errorMsgbirthdayValidationModel.text!=''}&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;local:BirthdayValidator</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">id</span>=<span class="st0">&quot;birthdayVal&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">required</span>=<span class="st0">&quot;true&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">source</span>=<span class="st0">&quot;{birthdayValidationModel}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">property</span>=<span class="st0">&quot;birthday&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">listener</span>=<span class="st0">&quot;{errorMsgbirthdayValidationModel}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">trigger</span>=<span class="st0">&quot;{year}&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">triggerEvent</span>=<span class="st0">&quot;focusOut&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">invalid</span>=<span class="st0">&quot;onInvalidHandler(event)&quot;</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">valid</span>=<span class="st0">&quot;onValidHandler(event)&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <br />
<span class="sc3"><span class="re1">&lt;/mx:Application<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></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://dekwant.eu/?feed=rss2&amp;p=73</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To: Load a spring application from a jar file</title>
		<link>http://dekwant.eu/?p=63</link>
		<comments>http://dekwant.eu/?p=63#comments</comments>
		<pubDate>Mon, 24 Aug 2009 07:18:59 +0000</pubDate>
		<dc:creator>mdekwant</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 configure this in [...]]]></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">package</span> <span class="co2">nl.foo.bar.dao</span><span class="sy0">;</span><br />
<br />
<span class="kw1">import</span> <span class="co2">org.springframework.stereotype.Repository</span><span class="sy0">;</span><br />
<br />
<span class="kw1">import</span> <span class="co2">nl.foo.bar.domain.GOClass</span><span class="sy0">;</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 class="kw3">Repository</span></a><span class="br0">&#40;</span><span class="st0">&quot;goClassDAO&quot;</span><span class="br0">&#41;</span><br />
<span class="kw1">public</span> <span class="kw1">class</span> GOClassDAOJPA <span class="kw1">extends</span> BaseDAOJPA<span class="sy0">&lt;</span>GOClass<span class="sy0">&gt;</span> <span class="kw1">implements</span> GOClassDAO <span class="br0">&#123;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>ApplicationContext-dao.xml</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;context:component-scan</span> <span class="re0">base-package</span>=<span class="st0">&quot;nl.foo.bar.dao&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;context:include-filter</span> <span class="re0">type</span>=<span class="st0">&quot;annotation&quot;</span></span><br />
<span class="sc3"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">expression</span>=<span class="st0">&quot;org.springframework.stereotype.Repository&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/context:component-scan<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>ApplicationContext-controller.xml (this gets loaded from my swing application)</p>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="xml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc3"><span class="re1">&lt;import</span> <span class="re0">resource</span>=<span class="st0">&quot;classpath:ApplicationContext-dao.xml&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;context:annotation-config</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;context:component-scan</span> <span class="re0">base-package</span>=<span class="st0">&quot;nl.foo.bar.gui.controller&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;context:include-filter</span> <span class="re0">type</span>=<span class="st0">&quot;annotation&quot;</span> &nbsp; &nbsp;</span><br />
<span class="sc3"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">expression</span>=<span class="st0">&quot;org.springframework.stereotype.Controller&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/context:component-scan<span class="re2">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Code snippet from my swing application</p>
<div class="codecolorer-container java mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> locations <span class="sy0">=</span> <span class="br0">&#123;</span><span class="st0">&quot;ApplicationContext-controller.xml&quot;</span><span class="br0">&#125;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; ClassPathXmlApplicationContext ctx <span class="sy0">=</span> <span class="kw1">new</span> ClassPathXmlApplicationContext<span class="br0">&#40;</span>locations<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; ApplicationController appController <span class="sy0">=</span> <span class="br0">&#40;</span>ApplicationController<span class="br0">&#41;</span>ctx.<span class="me1">getBean</span><span class="br0">&#40;</span><span class="st0">&quot;applicationController&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></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://dekwant.eu/?feed=rss2&amp;p=63</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webservices with Spring and Castor</title>
		<link>http://dekwant.eu/?p=24</link>
		<comments>http://dekwant.eu/?p=24#comments</comments>
		<pubDate>Mon, 17 Aug 2009 09:33:19 +0000</pubDate>
		<dc:creator>mdekwant</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 Castor.
There [...]]]></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://dekwant.eu/wp-content/uploads/2009/06/newmavenproject1.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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">[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></td></tr></tbody></table></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://dekwant.eu/wp-content/uploads/2009/06/newmavenwebproject.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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">[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></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">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></td></tr></tbody></table></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://dekwant.eu/?feed=rss2&amp;p=24</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy JavaScript client-side form validation</title>
		<link>http://dekwant.eu/?p=7</link>
		<comments>http://dekwant.eu/?p=7#comments</comments>
		<pubDate>Wed, 03 Jun 2009 07:46:00 +0000</pubDate>
		<dc:creator>mdekwant</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-7"></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sy0">&lt;</span>script src<span class="sy0">=</span><span class="st0">&quot;fvalidation.js&quot;</span> language<span class="sy0">=</span><span class="st0">&quot;JavaScript&quot;</span> type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="sy0">&gt;&lt;/</span>script<span class="sy0">&gt;</span></div></td></tr></tbody></table></div>
</p>
<p><strong>Add the validation attribute in the form-tag</strong></p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sy0">&lt;</span>form <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;simpleform&quot;</span> validate<span class="sy0">=</span><span class="st0">&quot;onsubmit&quot;</span><span class="sy0">&gt;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sy0">&lt;</span>input <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;huisnummer&quot;</span> mask<span class="sy0">=</span><span class="st0">&quot;999&quot;</span> type<span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="sy0">/&gt;</span></div></td></tr></tbody></table></div>
<p><strong>Date check</strong></p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sy0">&lt;</span>input <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;geboortedatum&quot;</span> check<span class="sy0">=</span><span class="st0">&quot;date_iso&quot;</span> type<span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="sy0">/&gt;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">messages<span class="sy0">=</span><span class="st0">&quot;global&quot;</span></div></td></tr></tbody></table></div>
</p>
<p>and Put a message container in your code like this:</p>
<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;global&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;globalError&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">messages<span class="sy0">=</span><span class="st0">&quot;local&quot;</span></div></td></tr></tbody></table></div>
</p>
<p>and provide a span-tag for each input-tag you have validation on:</p>
<p><div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;naam_error&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;localError&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/span.html"><span class="kw2">span</span></a>&gt;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="sc2">&lt;<a href="http://december.com/html/4/element/input.html"><span class="kw2">input</span></a> <span class="kw3">name</span><span class="sy0">=</span><span class="st0">&quot;naam&quot;</span> custom<span class="sy0">=</span><span class="st0">&quot;exampleCustomCheck('Custom&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="sy0">/</span>&gt;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw2">function</span> exampleCustomCheck<span class="br0">&#40;</span>message<span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="sy0">&lt;</span>br <span class="sy0">/&gt;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span>document.<span class="me1">simpleform</span>.<span class="me1">naamCustom</span>.<span class="me1">value</span><span class="sy0">!=</span><span class="st0">''</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">null</span><span class="sy0">;&lt;</span>br <span class="sy0">/&gt;</span><br />
<span class="kw1">return</span> message<span class="sy0">;&lt;</span>br <span class="sy0">/&gt;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">mask<span class="sy0">=</span><span class="st0">&quot;9999 AA&quot;</span></div></td></tr></tbody></table></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 mac-classic" style="overflow:auto;white-space:nowrap;width:435px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="javascript codecolorer" style="font-family:Monaco,Lucida Console,monospace">mask<span class="sy0">=</span><span class="st0">&quot;XX-XX-99&quot;</span></div></td></tr></tbody></table></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://dekwant.eu/?feed=rss2&amp;p=7</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
