<?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>Jon Lebensold &#187; AJAX</title>
	<atom:link href="http://lebensold.net/category/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://lebensold.net</link>
	<description>thoughts on web development, technology and media</description>
	<lastBuildDate>Tue, 22 Jun 2010 16:04:05 +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>Changing Times Bahá&#8217;í Conference Website Launched &#8211; Making Zend, WordPress and Flickr Friends</title>
		<link>http://lebensold.net/creative-stuff/changing-times-bahai-conference-website-launched-making-zend-wordpress-and-flickr-friends</link>
		<comments>http://lebensold.net/creative-stuff/changing-times-bahai-conference-website-launched-making-zend-wordpress-and-flickr-friends#comments</comments>
		<pubDate>Thu, 11 Sep 2008 20:56:24 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Bahá'í]]></category>
		<category><![CDATA[Creative stuff]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/?p=207</guid>
		<description><![CDATA[I had the opportunity to work with a ]]></description>
			<content:encoded><![CDATA[<p>I had the opportunity to work with a <a href="http://www.flickr.com/photos/ezrah/"designer and friend of mine</a> on a website for <a href="http://www.changing-times.org">an international Bahá'í youth conference</a>. </p>
<p>From a technical perspective, the website was pretty trivial, however I was able to experiment with the Zend Framework's Flickr web service implementation. Caching the images and resizing them was a must since Flickr doesn't offer great options with the image presets (unless you ask people to upload at a special resolution... which is no fun!)</p>
<p>Building an AJAX slideshow that's driven off of Flickr meant I didn't have to write any upload-image code for the client. Furthermore, they can use Flickr pools during the conference to create an ever-up-to date gallery. </p>
<p>I'll be releasing this as a WordPress plugin that's a little more user friendly, however if you're doing something similar and need a hand, leave a comment and I'll send you what I wrote.  </p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/creative-stuff/changing-times-bahai-conference-website-launched-making-zend-wordpress-and-flickr-friends/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dojo and Zend: Where&#8217;s the loose coupling gone?</title>
		<link>http://lebensold.net/zend/dojo-and-zend-wheres-the-loose-coupling-gone</link>
		<comments>http://lebensold.net/zend/dojo-and-zend-wheres-the-loose-coupling-gone#comments</comments>
		<pubDate>Wed, 13 Aug 2008 20:28:50 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[dojo]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/?p=151</guid>
		<description><![CDATA[On the eve of the release of the Zend Framework's 1.6RC, found it interesting to read Lukas' comment on Matthew Weier O'Phinney's blog about how there were outstanding issues in existing core components of the Zend Framework that hadn't been resolved, and yet the Zend_* component library was still growing and accepting new proposals. 
The [...]]]></description>
			<content:encoded><![CDATA[<p>On the eve of the release of the Zend Framework's 1.6RC, found it interesting to read <a href='http://pooteeweet.org/'>Lukas</a>' comment on <a href='http://weierophinney.net/matthew/'>Matthew Weier O'Phinney's blog</a> about how there were outstanding issues in existing core components of the Zend Framework that hadn't been resolved, and yet the Zend_* component library was still growing and accepting new proposals. </p>
<p>The last comment by Martin noted that Zend_Db still had some unresolved issues for over a year. </p>
<p>Matthew's response was that this was a community project and that priorities are dictated as such. Personally, this doesn't affect me because I'm hedging my bets on Doctrine as an ORM layer for PHP development. </p>
<p>I like Matthew's response because the Zend Framework's philosophy encourages the development of loosely coupled components wrapped up in a development philosophy that encourages open contributions, financial backing (thanks to Zend, IBM, Sun and others), Unit Testing and project transparency. Here's where things go a little wonky.</p>
<h1>Partnership with the Dojo community</h1>
<p>While I really enjoy the implementation of Zend_Form on the server side. It allows multiple configurations, supports validation and while the decorators are a bit obtuse, on a whole, the Zend_Form libraries thin out controllers and encapsulate the concern of data entry in a clean manner.</p>
<p>In this point release, however it seems like there's been a whole outgrowth of Zend_Dojo_* classes that cater to doing AJAX development with the Dojo stack. I'm not sold on Dojo as a client-side framework. Past experience with it has left me trying to sort out a large, over-specialized collection of patterns that almost do what I want but not quite. I also don't like the coupling that occurs between the data set, the client-side validation and the magic rendering of panels (like Accordian's and content panes). </p>
<h1>An alternative architectural approach</h1>
<p>I would rather write the events, the theme, the data and the validation separately and reduce duplication in each of those patterns rather than in the UI pattern as a whole. In short, I think they've abstracted the wrong part. The same example can be seen in ASP.NET form validators from two years ago.</p>
<p>With Prototype, I can rapidly mock out a site with the functional requirements and use Script.aculo.us to accent the presentation with animation. My functional specification isn't muddied with fancy visuals and it lets me focus on the event handling, validation and end states rather than the fancy effects.</p>
<p>By using Zend_Dojo, you won't be tempted to build a well-exposed Service Layer from Zend_Controller. The advantage here is that you lead development towards service-orientation. If you need to write a Flex front-end, or a whole new business-tier, you at least have the beginnings of a web service, whereas if your working with Zend_Dojo's declarative templating syntax, you're already coupling the events, validation and data into heavily abstracted UI patterns.</p>
<p>This approach doesn't lead development towards the production of a refined Service Layer, but to a specialized Dojo-friendly interface with markup-generation from Zend_Form classes into Dojo markup. I would rather see a Zend_Form Service API where developers can send / receive JSON messages to inherited Zend_Form and then have the Dojo community write an Adapter that would send / receive messages from Dojo widgets.</p>
<p>A year or two from now, I wouldn't be surprised if people will look at the same Zend bug tracker, asking where support for Dojo went after the Zend team jumps to the next cool Javascript framework on the block and we find ourselves with Zend_Form_SproutCore or some other dependency.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/zend/dojo-and-zend-wheres-the-loose-coupling-gone/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Decoupled validation with Zend_Form, Zend_Validate and Zend MVC</title>
		<link>http://lebensold.net/development/decoupled-validation-with-zend_form-zend_validate-and-zend-mvc</link>
		<comments>http://lebensold.net/development/decoupled-validation-with-zend_form-zend_validate-and-zend-mvc#comments</comments>
		<pubDate>Wed, 04 Jun 2008 19:56:32 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[free code]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/decoupled-validation-with-zend_form-zend_validate-and-zend-mvc</guid>
		<description><![CDATA[Lately I've been experimenting a lot with trying to serialize a form and send it over the wire as a means of doing asynchronous postback of partially validated forms. 
I've come up with a little prototype that's a PHP version of an ASP.NET implementation I did a couple months ago for a project I was [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I've been experimenting a lot with trying to serialize a form and send it over the wire as a means of doing asynchronous postback of partially validated forms. </p>
<p>I've come up with a little prototype that's a PHP version of an ASP.NET implementation I did a couple months ago for a project I was working on. </p>
<p>The PHP version was surprisingly easier to implement, due to the simplicity of Zend_Form when compared to the bulldozer we-control-everything-and-rewrite-your-user-control-id's approach of ASP.NET forms.</p>
<p>Essentially, I've created a class with a simple form (1 lookup list (one-to-many for the data modelers out there) and a couple of simple textboxes).</p>
<p>While I think that it's crucial to decouple business rules from the actual form implementation, I think that Zend_Validate validators, as well as custom validators, are an excellent way of creating testable, declaritive validation rules that can be applied to form elements as you see fit. The other decoupling you'll find in this example is from the postback model, essentially allowing you to drop the same form into any part of a Zend Framework application and posting to an Ajax Controller service for validation purposes. What's nice about this is that no business rules are left on the client. I've used prototype for a little styling.</p>
<p>The finishing touch in all of this is that I can leverage the server-side validation routine for both the asynchronous and synchronous calls, so that postback and validation run through the same validation code, essentially providing a second interface with to the same form object.</p>
<p>I'm going to look into extending this example to provide not only one-to-one mapping and one-to-many mapping (lookup lists), but also many-to-one mapping (generating sub-forms dynamically and performing partial validation). Not sure exactly how to do that, so comments would be greatly appreciated!</p>
<p>Here's a quick demonstration.<br />
<iframe src="http://jon.lebensold.ca/demo/decoupled-validation/html/" width="550" height="450" border="0"></iframe></p>
<p>and now for the code. The webservice bit is all contained in the IndexController for the sake of brevity. In a full blown application, you would likely have a Controller (or several controllers) that would offer different asynchronous entry points into your MVC framework.</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">class</span> IndexController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">f</span> = <span style="color: #000000; font-weight: bold;">new</span> RegistrationForm<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">setMode</span> = <span style="color: #ff0000;">&quot;setMode($('wsTab').childNodes[0]);&quot;</span>;
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">f</span>-&gt;<span style="color: #006600;">isValid</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">render</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;FormSuccess&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;_request-&gt;<span style="color: #006600;">isPost</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">errorElements</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">f</span>-&gt;<span style="color: #006600;">getMessages</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span>-&gt;<span style="color: #006600;">setMode</span> = <span style="color: #ff0000;">&quot;setMode($('pbTab').childNodes[0]);&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Ajax JSON call is made through this controller
	 *
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> asyncAction<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">//prepare a JSON response</span>
		<span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span>-&gt;<span style="color: #006600;">setNoRender</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'layout'</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">disableLayout</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
     	<span style="color: #808080; font-style: italic;">//Map the form from the client-side call</span>
     	<span style="color: #0000ff;">$myFormData</span> = Zend_Json::<span style="color: #006600;">decode</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">getParam</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;fs&quot;</span><span style="color: #66cc66;">&#41;</span> , Zend_Json::<span style="color: #006600;">TYPE_ARRAY</span><span style="color: #66cc66;">&#41;</span>;
     	<span style="color: #0000ff;">$form</span> = <span style="color: #000000; font-weight: bold;">new</span> RegistrationForm<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
     	<span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">isValid</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$myFormData</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
     	<span style="color: #808080; font-style: italic;">//return the result</span>
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getResponse</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">setHeader</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Content-Type'</span>, <span style="color: #ff0000;">'application/json'</span><span style="color: #66cc66;">&#41;</span>
							   -&gt;<span style="color: #006600;">setBody</span><span style="color: #66cc66;">&#40;</span>Zend_Json::<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$form</span>-&gt;<span style="color: #006600;">getMessages</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>You'll notice that I've pulled out the form into its own class (RegistrationForm): </p>
<pre class="php"><span style="color: #000000; font-weight: bold;">class</span> RegistrationForm <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form
<span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
    	<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setAttrib</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;id&quot;</span> , <span style="color: #ff0000;">&quot;frm&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	<span style="color: #0000ff;">$onetomany</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Select<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'sad'</span><span style="color: #66cc66;">&#41;</span>;
    	<span style="color: #0000ff;">$onetomany</span>-&gt;<span style="color: #006600;">setLabel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'One to many:'</span><span style="color: #66cc66;">&#41;</span>
    			  -&gt;<span style="color: #006600;">setMultiOptions</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getOneToMany</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    			  -&gt;<span style="color: #006600;">addValidator</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Onetomany<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">$usernameRequiredValidator</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Validate_NotEmpty<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$usernameRequiredValidator</span>-&gt;<span style="color: #006600;">setMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Please enter a username.&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">$usernameStringLengthValidator</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Validate_StringLength<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$usernameStringLengthValidator</span>-&gt;<span style="color: #006600;">setMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Username is too short! (8 character minimum)&quot;</span>, Zend_Validate_StringLength::<span style="color: #006600;">TOO_SHORT</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$usernameStringLengthValidator</span>-&gt;<span style="color: #006600;">setMessage</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Username is too long! (less than 20 characters)&quot;</span>, Zend_Validate_StringLength::<span style="color: #006600;">TOO_LONG</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	<span style="color: #0000ff;">$username</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Text<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'username'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$username</span>-&gt;<span style="color: #006600;">setLabel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Username:'</span><span style="color: #66cc66;">&#41;</span>
        		 -&gt;<span style="color: #006600;">addValidator</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$usernameRequiredValidator</span><span style="color: #66cc66;">&#41;</span>
        		 -&gt;<span style="color: #006600;">addValidator</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$usernameStringLengthValidator</span><span style="color: #66cc66;">&#41;</span>
        		 -&gt;<span style="color: #006600;">setRequired</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    	<span style="color: #0000ff;">$name</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Text<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'name'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$name</span> -&gt;<span style="color: #006600;">setLabel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Name:'</span><span style="color: #66cc66;">&#41;</span>
        		 -&gt;<span style="color: #006600;">addValidator</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'StringLength'</span>, <span style="color: #000000; font-weight: bold;">true</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        		 -&gt;<span style="color: #006600;">setRequired</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;    	
&nbsp;
        <span style="color: #0000ff;">$password</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_Password<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'password'</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$password</span>-&gt;<span style="color: #006600;">setLabel</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'password:'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">addElements</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
        	<span style="color: #0000ff;">$onetomany</span>,
            <span style="color: #0000ff;">$username</span>,
            <span style="color: #0000ff;">$name</span>,
            <span style="color: #0000ff;">$password</span>
&nbsp;
        <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setDecorators</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
        	<span style="color: #ff0000;">'FormElements'</span>,
            <span style="color: #ff0000;">'Fieldset'</span>,
            <span style="color: #ff0000;">'Form'</span>
&nbsp;
        <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getElements</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$element</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
        	<span style="color: #0000ff;">$element</span>-&gt;<span style="color: #006600;">setDecorators</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
                     <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ViewHelper'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'class'</span> =&gt; <span style="color: #ff0000;">'formText'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,
                     <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Label'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'class'</span> =&gt; <span style="color: #ff0000;">'label'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,
            		 <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'HtmlTag'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'tag'</span> =&gt; <span style="color: #ff0000;">'dd'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                 <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #0000ff;">$element</span>-&gt;<span style="color: #006600;">class</span> = <span style="color: #ff0000;">'formText'</span>;
&nbsp;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getOneToMany<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$ar</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;please select&quot;</span>;
		<span style="color: #0000ff;">$ar</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;car&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;car&quot;</span>;
		<span style="color: #0000ff;">$ar</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;rollerBlade&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;roller blades&quot;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$ar</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>In my post about enterprise validation, I described a scenario where you would create custom validators that could be applied declaratively in C# using the Enterprise Library. The same thinking was applied here with the One To Many by creating a custom validator. This allows you to test the validation (and your business rules) without thinking about the form, the UI or even session:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">class</span> Onetomany <span style="color: #000000; font-weight: bold;">extends</span> Zend_Validate_Abstract
<span style="color: #66cc66;">&#123;</span>
    const NOT_VALID  = <span style="color: #ff0000;">'stringLengthTooLong'</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * @var array
     */</span>
    protected <span style="color: #0000ff;">$_messageTemplates</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
        self::<span style="color: #006600;">NOT_VALID</span> =&gt; <span style="color: #ff0000;">&quot;one to many was not valid choice&quot;</span>,
&nbsp;
    <span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * @var array
     */</span>
    protected <span style="color: #0000ff;">$_messageVariables</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span>
        <span style="color: #ff0000;">'not_valid'</span> =&gt; <span style="color: #ff0000;">'_not_valid'</span>,
&nbsp;
    <span style="color: #66cc66;">&#41;</span>;
&nbsp;
    protected <span style="color: #0000ff;">$_not_valid</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * Returns the min option
     *
     * @return integer
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getNotValid<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;_not_valid;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * Defined by Zend_Validate_Interface
     * @param  string $value
     * @return boolean
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isValid<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// more business rules would go somewhere here...</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$value</span> == <span style="color: #ff0000;">&quot; &quot;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #0000ff;">$this</span>-&gt;_error<span style="color: #66cc66;">&#40;</span>self::<span style="color: #006600;">NOT_VALID</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/count"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;_messages<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>The last bit of magic is the Javascript. My weapon of choice (as mentioned above) is prototype, however I'm sure you could do the same thing with any other javascript framework:</p>
<pre class="javascript">Event.<span style="color: #006600;">observe</span><span style="color: #66cc66;">&#40;</span>window , <span style="color: #3366CC;">&quot;load&quot;</span> , <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
		&lt;?= $this-&gt;setMode ?&gt;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #003366; font-weight: bold;">function</span> attachWebServiceObserver<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> url = <span style="color: #3366CC;">&quot;/index/async/&quot;</span>;
		<span style="color: #003366; font-weight: bold;">var</span> f = JSON.<span style="color: #006600;">stringify</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'frm'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">serialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #006600;">Request</span><span style="color: #66cc66;">&#40;</span>url , <span style="color: #66cc66;">&#123;</span>
			method: <span style="color: #3366CC;">'post'</span>,
			parameters: <span style="color: #3366CC;">'fs='</span> + f,
			onComplete : doAjaxCall.<span style="color: #006600;">bindAsEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> attachPostBackObserver<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'frm'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">submit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">//this ID comes from the RegistrationForm class</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> setMode<span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	$$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'.tab'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>emt<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> emt.<span style="color: #006600;">setStyle</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#123;</span>background : <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	e.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>background :<span style="color: #3366CC;">&quot;#FFFF99&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>!FIRST_LOAD<span style="color: #66cc66;">&#41;</span>
		clearErrors<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>e.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">id</span> ==<span style="color: #3366CC;">&quot;wsTab&quot;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		Event.<span style="color: #006600;">observe</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'bt'</span>, <span style="color: #3366CC;">'click'</span>, attachWebServiceObserver<span style="color: #66cc66;">&#41;</span>;
		Event.<span style="color: #006600;">stopObserving</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'bt'</span>, <span style="color: #3366CC;">'click'</span>, attachPostBackObserver<span style="color: #66cc66;">&#41;</span>;
		$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'bt'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">value</span> = <span style="color: #3366CC;">&quot;Submit Asynchronously&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>e.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">id</span> ==<span style="color: #3366CC;">&quot;pbTab&quot;</span> <span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		Event.<span style="color: #006600;">stopObserving</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'bt'</span>, <span style="color: #3366CC;">'click'</span>, attachWebServiceObserver<span style="color: #66cc66;">&#41;</span>;
		Event.<span style="color: #006600;">observe</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'bt'</span>,<span style="color: #3366CC;">'click'</span>, attachPostBackObserver<span style="color: #66cc66;">&#41;</span>;
		$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'bt'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">value</span> = <span style="color: #3366CC;">&quot;Submit With Postback&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	FIRST_LOAD = <span style="color: #003366; font-weight: bold;">false</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> doAjaxCall<span style="color: #66cc66;">&#40;</span>tr<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	clearErrors<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>formIsValid<span style="color: #66cc66;">&#40;</span>tr.<span style="color: #006600;">responseJSON</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'frm'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">submit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	displayErrorMessages<span style="color: #66cc66;">&#40;</span>tr.<span style="color: #006600;">responseJSON</span><span style="color: #66cc66;">&#41;</span>;	
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> clearErrors<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'dvPostbackErrors'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">update</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'dvPostbackErrors'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	$$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;.errormessage&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		Element.<span style="color: #006600;">remove</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	$$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;input.formText &quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		e.<span style="color: #006600;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>border : <span style="color: #3366CC;">&quot;1px solid #CCC&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	$$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;select.formText &quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>e<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		e.<span style="color: #006600;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>border : <span style="color: #3366CC;">&quot;1px solid #CCC&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> formIsValid<span style="color: #66cc66;">&#40;</span>errorJson<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>isNaN<span style="color: #66cc66;">&#40;</span>errorJson<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> displayErrorMessages<span style="color: #66cc66;">&#40;</span>errorJson<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>formElement <span style="color: #000066; font-weight: bold;">in</span> errorJson<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> elementObj = <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;errorJson.&quot;</span>+formElement<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>error <span style="color: #000066; font-weight: bold;">in</span> elementObj<span style="color: #66cc66;">&#41;</span>
			displayError<span style="color: #66cc66;">&#40;</span>formElement , <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;errorJson.&quot;</span>+formElement+<span style="color: #3366CC;">&quot;.&quot;</span>+error<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> displayError<span style="color: #66cc66;">&#40;</span>emt , msg<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> tpl = <span style="color: #3366CC;">&quot;&lt;span class='errormessage' &gt;&quot;</span>+msg+<span style="color: #3366CC;">&quot;&lt;/span&gt;&quot;</span>;
&nbsp;
	markInvalidTextbox<span style="color: #66cc66;">&#40;</span>emt<span style="color: #66cc66;">&#41;</span>;
&nbsp;
	Element.<span style="color: #006600;">insert</span><span style="color: #66cc66;">&#40;</span>emt , <span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">&quot;after&quot;</span> : tpl <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> markInvalidTextbox<span style="color: #66cc66;">&#40;</span>emt<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
	$<span style="color: #66cc66;">&#40;</span>emt<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">setStyle</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>border: <span style="color: #3366CC;">&quot;2px solid red&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>In the version that you can download, I include the <a href="http://www.json.org/js.html">JSON.stringify class</a> (courtesy of Crawford) to serialize the form and send it the AsyncAction in my IndexController.</p>
<p>This architectural approach allows you to keep all the validation rules server-side, while allowing you to pick and choose when and how you postback. Because this example works with both postback and asynchronous calls, it's a little verbose. </p>
<p>Regardless, you can <a href="http://jon.lebensold.ca/wp-content/uploads/2008/AsyncValidationManager.zip">download the whole project and try it out for yourself</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/decoupled-validation-with-zend_form-zend_validate-and-zend-mvc/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Screencast: Simple AJAX with the Prototype Javascript Framework</title>
		<link>http://lebensold.net/development/screencast-simple-ajax-with-the-prototype-javascript-framework</link>
		<comments>http://lebensold.net/development/screencast-simple-ajax-with-the-prototype-javascript-framework#comments</comments>
		<pubDate>Wed, 30 Apr 2008 06:46:04 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[demo]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/screencast-simple-ajax-with-the-prototype-javascript-framework</guid>
		<description><![CDATA[This is part two of my introductory Javascript videos. I cover how more about using Event Listeners in with the prototype javascript framework. I also try and answer the question: "What is an Event Listener?" and try and provide a simple example of doing an asynchronous call.
Unlike most AJAX samples, this example doesn't require any [...]]]></description>
			<content:encoded><![CDATA[<p>This is part two of my introductory Javascript videos. I cover how more about using Event Listeners in with the prototype javascript framework. I also try and answer the question: "What is an Event Listener?" and try and provide a simple example of doing an asynchronous call.</p>
<p>Unlike most AJAX samples, this example <strong>doesn't require any server-side scripting or even a webserver</strong>.</p>
<p>Two notes about the video;<br />
- It's not necessary to capture elements in Event.observe using $()<br />
e.g. Event.observe('myHelloLink' ...) instead of Event.observe($('myHelloLink') ... );</p>
<p>- Instead of using innerHTML, you can also use .update("text changed on Load");</p>
<p>Enjoy! </p>
<p><center><br />
<object type="application/x-shockwave-flash" align="center" width="480" height="270"  data="http://www.idea22.com/public/swf/i22_swf.swf?vv=videos:200804226044250710:480:270:e"><param name="allowScriptAccess" value="always" /><param name="movie" value="http://www.idea22.com/public/swf/i22_flv.swf?vv=pv:200804226044250710:480:270:e" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="allowfullscreen=true&logo=http://www.idea22.com/public/swf/i22.png&autostart=false&file=http://www.idea22.com/public/pv/200804226044250710.flv&image=http://www.idea22.com/public/pv/200804226044250710.jpg" /><embed src="http://www.idea22.com//public/swf/i22_flv.swf?vv=pv:200804226044250710:480:270:e" quality="high" width="480" width="270" id="idea22" align="center"  allowfullscreen="true" type="application/x-shockwave-flash"<br />
		pluginspage="http://www.macromedia.com/go/getflashplayer" flashVars="allowfullscreen=true&logo=http://www.idea22.com/public/swf/i22.png&autostart=false&file=http://www.idea22.com/public/pv/200804226044250710.flv&image=http://www.idea22.com/public/pv/200804226044250710.jpg" /></object></center></p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/screencast-simple-ajax-with-the-prototype-javascript-framework/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Screencast: Introduction to Javascript using Prototype</title>
		<link>http://lebensold.net/development/screencast-introduction-to-javascript-using-prototype</link>
		<comments>http://lebensold.net/development/screencast-introduction-to-javascript-using-prototype#comments</comments>
		<pubDate>Mon, 28 Apr 2008 06:51:05 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Screencasts]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/screencast-introduction-to-javascript-using-prototype</guid>
		<description><![CDATA[I've been meaning to do some introductory Javascript screencasts for awhile. In this short (15-minute) video, I cover basic usage of Prototype and some key best-practices for writing javascript code. There's a bit of fumbling since I'm still new to this. Comments are greatly appreciated.


]]></description>
			<content:encoded><![CDATA[<p>I've been meaning to do some introductory Javascript screencasts for awhile. In this short (15-minute) video, I cover basic usage of <a href="http://www.prototypejs.org">Prototype</a> and some key best-practices for writing javascript code. There's a bit of fumbling since I'm still new to this. Comments are greatly appreciated.</p>
<p><center><br />
<object type="application/x-shockwave-flash" align="center" width="480" height="270"  data="http://www.idea22.com/public/swf/i22_swf.swf?vv=videos:200804206043385650:480:270:e"><param name="allowScriptAccess" value="always" /><param name="movie" value="http://www.idea22.com/public/swf/i22_flv.swf?vv=pv:200804206043385650:480:270:e" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="allowfullscreen=true&logo=http://www.idea22.com/public/swf/i22.png&autostart=false&file=http://www.idea22.com/public/pv/200804206043385650.flv&image=http://www.idea22.com/public/pv/200804206043385650.jpg" /><embed src="http://www.idea22.com//public/swf/i22_flv.swf?vv=pv:200804206043385650:480:270:e" quality="high" width="480" width="270" id="idea22" align="center"  allowfullscreen="true" type="application/x-shockwave-flash"<br />
		pluginspage="http://www.macromedia.com/go/getflashplayer" flashVars="allowfullscreen=true&logo=http://www.idea22.com/public/swf/i22.png&autostart=false&file=http://www.idea22.com/public/pv/200804206043385650.flv&image=http://www.idea22.com/public/pv/200804206043385650.jpg" /></object></center></p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/screencast-introduction-to-javascript-using-prototype/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ASP.NET AJAX Validation using Enterprise Library Validation Block</title>
		<link>http://lebensold.net/development/aspnet-ajax-validation-using-enterprise-library-validation-block</link>
		<comments>http://lebensold.net/development/aspnet-ajax-validation-using-enterprise-library-validation-block#comments</comments>
		<pubDate>Sat, 19 Apr 2008 07:57:24 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/aspnet-ajax-validation-using-enterprise-library-validation-block</guid>
		<description><![CDATA[We all loathe writing validation for form elements, however no web developer would be worth their salt if they didn't incorporate at least server-side validation on forms. The problem arises when we're asked to provide client-side validation. With the ever increasing ubiquity of Javascript adoption due to the recent AJAX craze, I think it's safe [...]]]></description>
			<content:encoded><![CDATA[<p>We all loathe writing validation for form elements, however no web developer would be worth their salt if they didn't incorporate at least server-side validation on forms. The problem arises when we're asked to provide client-side validation. With the ever increasing ubiquity of Javascript adoption due to the recent AJAX craze, I think it's safe to say that we'll see a resurgence of fat-clients built inside a browser. </p>
<p><strong>The Purpose<br />
</strong>As forms become more complex, there is greater incentive to minimize trips to the server. Furthermore, ASP.NET doesn't play nice with dynamically generated controls (something that occurs with any moderate AJAX development. The following is a way of utilizing the tools in the Microsoft ASP.NET framework without rewriting key components (for an example of this, look at the MonoRail project or the new Microsoft MVC framework).</p>
<p>In the Microsoft camp, usually you're encouraged to use validators that let act as decorators to existing ASP.NET textboxes and other form elements. To make matters more complicated, the Patterns and Practices group as well as the AJAX.NET group in Microsoft have competing components for dealing with client-side validation.</p>
<p>I propose a third method that employs a webservice and allows you to dynamically generate your validation through an asynchronous postback of your form to the server. I've been testing this approach and I've been pretty successful thus far:</p>
<p><img src="http://jon.lebensold.ca/wp-content/uploads/2008/04/EnterpriseValidationSuggestion.png" height="80%" width="80% vspace="4" alt="Enterprisevalidationsuggestion" /></p>
<p><strong>On Using a Data Transfer Object (DTO)<br />
</strong>A Data Transfer object is simply a container where you can store a collection of variables in an organized manner. A DTO doesn't have any behaviour, just public properties. For example, an Employee object might have the following properties:</p>
<pre lang="c#" >
	Employee employee = EmployeeRepository.GetNewEmployee();
	employee.HiredAt = DateTime.Now();
	employee.Position = "Sales Manager";
	employee.OfficeExtension = 4556;
</pre>
<p>To simplify things, I use Castleproject's ActiveRecord libraries to create a simple relationship between my database tables and my DTO's.</p>
<p>I've broken down the requests in terms of a linear timeline of events on the page.</p>
<p><strong>Why Bother Mapping to a Data Transfer Object?</strong><br />
The Microsoft Enterprise Library enables you to decorate public properties (as well as methods) with validators. Furthermore, you create custom validators and include them in the same infrastructure that Microsoft provides for its own validators.</p>
<p><strong>1) The page is rendered and delivered to the client's browser</strong>: for the most part, it's just a plain old aspx page. However, I've made certain minor modifications that help later on in the dynamic mapping of a DTO from the form back to the server:</p>
<p>A form element looks something like this:</p>
<pre>&nbsp;
	&lt;ASP:TextBox id=&quot;tbEmployeePosition&quot; dto=&quot;Employee&quot; property=&quot;Position&quot; runat=&quot;server&quot; /&gt;
&nbsp;</pre>
<p>In my form, I've provided two attributes, dto and property, which can be used on in the web service to dynamically map the form elements back to the DTO for validation.</p>
<p><strong>2)</strong> <strong>Use a fake button to post the form asynchronously to a webservice in your project:</strong> all the latest javascript frameworks (my personal favourite is Prototype) support form serialization through utility of helper methods (see $F() in prototype). The JSON object you want to send to the webservice might look like this:</p>
<pre class="javascript">&nbsp;
<span style="color: #66cc66;">&#123;</span> <span style="color: #3366CC;">&quot;EmployeeForm&quot;</span> :
    <span style="color: #66cc66;">&#91;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;id&quot;</span> : <span style="color: #3366CC;">&quot;aspnet_dynamic_form_tbEmployeePosition&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;value&quot;</span> : <span style="color: #3366CC;">&quot;Sales Manager&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;property&quot;</span> : <span style="color: #3366CC;">&quot;Position&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;dto&quot;</span> : <span style="color: #3366CC;">&quot;Employee&quot;</span><span style="color: #66cc66;">&#93;</span>
     <span style="color: #66cc66;">&#93;</span>
&nbsp;
    <span style="color: #66cc66;">&#91;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;id&quot;</span> : <span style="color: #3366CC;">&quot;aspnet_dynamic_form_tbEmployeeOfficeExtension&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;value&quot;</span> : <span style="color: #3366CC;">&quot;4556&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;property&quot;</span> : <span style="color: #3366CC;">&quot;OfficeExtension&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;dto&quot;</span> : <span style="color: #3366CC;">&quot;Employee&quot;</span><span style="color: #66cc66;">&#93;</span>
     <span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p><strong>3) The Mapping Layer grabs a DTO from the Repository and maps the values using the Data from the JSON posted to the webservice:</strong> it's very easy to take this data and, using the PropertyInfo class and a bit of type checking, map these values to a DTO. Once their mapped, you can easily run Entlib Validation.</p>
<p><strong>4) The ValidationManager validates the DTO, collects the EntLib Validation messages in a Hashtable: </strong>The Hashtable can have a key / value pair with the submitted form element's ID and the error message associated with the invalid element. Error messages are pulled from the MessageTemplate field in your validator's, whether you're adding attributes, or adding validation through your web.config.</p>
<p><strong>5) The Hashtable is returned to the client</strong>: Microsoft's webservices don't support Hashtables natively, however you can get around this by creating an ArrayList containing string[] objects.</p>
<p><strong>6) The values are inserted back onto the form:</strong> with a Hashtable containing element ID's and their respective messages, it becomes trivial to add these server-side messages to the client-side. In Prototype, it's a matter of <strong>Element.insert( responseJSON[i][0] , { "after" : "&lt;span class='error'&gt;"+responseJSON[i][1] + "&lt;/span&gt;" });</strong> where i corresponds with to the message in the list, 0 is the client's element ID and 1 is the message. </p>
<p><strong>7) The Form is automatically submitted to the server if the form is valid</strong>: if responseJSON is empty, we simply fire the <strong>.click();</strong> on the ASP.NET textbox as though the user did it himself. This means keeping track of the ASP.NET prefix which is added on all IDs that have the <strong>runat="server"</strong> directive. </p>
<p>The beauty of this approach is that it's highly extensible, you could serialize and post any part of your form if you needed to. Furthermore, the mapping that happens when the actual form controls are posted to the server would be nearly identical and the validation would be consolidated into one place. Lastly, you could provide the same error messages on server-side postback of the form (however it would be a little tricky to make them display as easily as it is with the web service.</p>
<p>I'll be providing a Zend sample of this in the week to come.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/aspnet-ajax-validation-using-enterprise-library-validation-block/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Demo: AJAX Autocompleter with Script.aculo.us and a Zend JSON web service</title>
		<link>http://lebensold.net/creative-stuff/demo-ajax-autocompleter-with-scriptaculous-and-a-zend-json-web-service</link>
		<comments>http://lebensold.net/creative-stuff/demo-ajax-autocompleter-with-scriptaculous-and-a-zend-json-web-service#comments</comments>
		<pubDate>Mon, 24 Mar 2008 09:16:52 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Creative stuff]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[free code]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/creative-stuff/demo-ajax-autocompleter-with-scriptaculous-and-a-zend-json-web-service</guid>
		<description><![CDATA[Today I'm posting a sample project of a modification of a Script.aculo.us auto-completer script that will work with a Zend JSON web service. This example could easily be expanded by providing a richer data collection to the client (currently it's just a string array).
Here's a demo:





    

Implementing the code is really only [...]]]></description>
			<content:encoded><![CDATA[<p>Today I'm posting a sample project of a <a href="http://wiki.script.aculo.us/scriptaculous/show/Autocompleter.Local">modification of a Script.aculo.us auto-completer script</a> that will work with a Zend JSON web service. This example could easily be expanded by providing a richer data collection to the client (currently it's just a string array).</p>
<p>Here's a demo:</p>
<link rel="stylesheet" type="text/css" href="/demo/html/public/css/autocomplete.css" >
<p><script type="text/javascript" src="/demo/html/public/js/prototype.js"></script></p>
<p><script type="text/javascript" src="/demo/html/public/js/scriptaculous-1.8/scriptaculous.js"></script></p>
<p><script type="text/javascript" src="/demo/html/public/js/autocompleter.js"></script></p>
<input id="tbAutoCompleter" name="tbAutoCompleter" />
<div id="dvAutoCompleter" class="auto_complete" >    </div>
<p><script type="text/javascript" src="/demo/wp_ac.js"></script></p>
<p>Implementing the code is really only one line once you have the back end web service configured:</p>
<pre class="javascript"> <span style="color: #003366; font-weight: bold;">var</span> demoAutocompleter = <span style="color: #003366; font-weight: bold;">new</span> MyAjaxAutocompleter<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'tbAutoCompleter'</span>, <span style="color: #3366CC;">'dvAutoCompleter'</span>, <span style="color: #3366CC;">'/demo/html/Ajaxservice/index'</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>where 'tbAutoCompleter' corresponds to the textbox you wish to bind, 'dvAutoCompleter' is the control in question and '/demo/html/Ajaxservice/index' is the actual Web service giving you JSON data.</p>
<p>I'm still having a hard time POSTing to a Zend controller in a manner as elegant as you would find in ASP.NET's web services, however the code isn't really that bad. My AjaxServiceController looks like this:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">class</span> AjaxserviceController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">contextSwitch</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
             -&gt;<span style="color: #006600;">addActionContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'index'</span>, <span style="color: #ff0000;">'json'</span><span style="color: #66cc66;">&#41;</span>
             -&gt;<span style="color: #006600;">initContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
       	<span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">viewRenderer</span>-&gt;<span style="color: #006600;">setNoRender</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
       	<span style="color: #0000ff;">$this</span>-&gt;_helper-&gt;<span style="color: #006600;">getHelper</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'layout'</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">disableLayout</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
       <span style="color: #808080; font-style: italic;">/* [Json response] */</span>
		 <span style="color: #0000ff;">$data</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;2008&quot;</span>,<span style="color: #ff0000;">&quot;3d&quot;</span>,<span style="color: #ff0000;">&quot;social&quot;</span>,<span style="color: #ff0000;">&quot;software&quot;</span>,<span style="color: #ff0000;">&quot;technology&quot;</span>,<span style="color: #ff0000;">&quot;tips&quot;</span>,
<span style="color: #ff0000;">&quot;tools&quot;</span>,<span style="color: #ff0000;">&quot;toread&quot;</span>,<span style="color: #ff0000;">&quot;travel&quot;</span>,<span style="color: #ff0000;">&quot;tutorial&quot;</span>,
<span style="color: #ff0000;">&quot;tutorials&quot;</span>,<span style="color: #ff0000;">&quot;tv&quot;</span>,<span style="color: #ff0000;">&quot;typography&quot;</span>, <span style="color: #ff0000;">&quot;wiki&quot;</span>,<span style="color: #ff0000;">&quot;windows&quot;</span>,<span style="color: #ff0000;">&quot;wishlist&quot;</span>,<span style="color: #ff0000;">&quot;wordpress&quot;</span>
,<span style="color: #ff0000;">&quot;work&quot;</span>,<span style="color: #ff0000;">&quot;writing&quot;</span>,<span style="color: #ff0000;">&quot;youtube&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		 <span style="color: #0000ff;">$responseData</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">array_isearch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">getParam</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'search'</span><span style="color: #66cc66;">&#41;</span> , <span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
       try <span style="color: #66cc66;">&#123;</span>
&nbsp;
           <span style="color: #0000ff;">$responseDataJsonEncoded</span> = Zend_Json::<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$responseData</span><span style="color: #66cc66;">&#41;</span>;
           <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">getResponse</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>-&gt;<span style="color: #006600;">setHeader</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Content-Type'</span>, <span style="color: #ff0000;">'application/json'</span><span style="color: #66cc66;">&#41;</span>
							   -&gt;<span style="color: #006600;">setBody</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$responseDataJsonEncoded</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
       <span style="color: #66cc66;">&#125;</span> catch<span style="color: #66cc66;">&#40;</span>Zend_Json_Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
           <span style="color: #808080; font-style: italic;">// handle and generate HTTP error code response, see below</span>
       <span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> array_isearch<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$str</span>, <span style="color: #0000ff;">$array</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    	<span style="color: #0000ff;">$returnArray</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$v</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/$str/i'</span>,<span style="color: #0000ff;">$v</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
            	<span style="color: #0000ff;">$returnArray</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$v</span>;
&nbsp;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$returnArray</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>There's not much here, mostly just disabling the Zend Layout, specifying the content and doing the search. The $data array could easily be replaced with a data source (like a collection from Zend_Db).</p>
<p><center><a style="border: 0px none #FFF;" href="/demo/SampleAutoCompletionZend15.zip"><img  style="border: 0px none #FFF;"src="/wp-content/uploads/2008/downloadSearchIcon.png" /><br />
<br />
Download Ajax Auto Completer Sample Zend Framework 1.5 project<br />
</a></center></p>
<p>The nice thing about web service AJAX controls is that they live independently of the application calling them, so you can essentially separate out your data layer in the same way that you would separate Zend_Db resources from a Zend_Controller.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/creative-stuff/demo-ajax-autocompleter-with-scriptaculous-and-a-zend-json-web-service/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AJAX Autocompleter with Script.aculo.us and an ASP.NET web service</title>
		<link>http://lebensold.net/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service</link>
		<comments>http://lebensold.net/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service#comments</comments>
		<pubDate>Fri, 21 Mar 2008 05:23:34 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service</guid>
		<description><![CDATA[Yesterday a Microsoft MVP had asked me to provide a better example of using the auto-completer that I had made with an ASP.NET project. In response to this, I'm uploading a project that has a fully-functioning example. The use of a web service instead of the AJAX ASP.NET toolkit allows you to embed your AJAXified [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday a Microsoft MVP had asked me to provide a better example of using the auto-completer that I had made with an ASP.NET project. In response to this, I'm uploading a project that has a fully-functioning example. The use of a web service instead of the AJAX ASP.NET toolkit allows you to embed your AJAXified controls inside of user controls rather than having them bound to a particular page. Furthermore, you can easily customize the script if you so choose.</p>
<p><center><a style="border: 0px none #FFF;" href="/wp-content/uploads/2008/AjaxAutoCompleterASPNET.zip"><img  style="border: 0px none #FFF;"src="/wp-content/uploads/2008/downloadSearchIcon.png" /><br />
<br />
Download Ajax Auto Completer Sample ASP.NET project<br />
</a></center></p>
<p>For example, take a look at line 301 of autocompleter.js:</p>
<pre class="javascript">&nbsp;
  choicesToHtml : <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>choices<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> output = <span style="color: #3366CC;">&quot;
&lt;ul&gt;&quot;</span>;
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>i=<span style="color: #CC0000;">0</span>; i&lt; choices.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span>
            output = output + <span style="color: #3366CC;">&quot;
&lt;li&gt;&quot;</span> + choices<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> + <span style="color: #3366CC;">&quot;&lt;/li&gt;
&nbsp;
&quot;</span>;
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> output + <span style="color: #3366CC;">&quot;&lt;/ul&gt;
&nbsp;
&quot;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>  Because you're actually pulling data from the web service, it would be easy to extend this example to provide a fully nested JSON object with images etc... as part of the auto-completer. I'll provide such an example with the Zend Framework and it's web service components at a later date, however being able to serialize a data structure like the one below would be perfect for an auto-completion web service.</p>
<pre class="javascript">&nbsp;
 <span style="color: #66cc66;">&#123;</span>
     <span style="color: #3366CC;">&quot;headerText&quot;</span>: <span style="color: #3366CC;">&quot;SearchBox Header Text&quot;</span>,
     <span style="color: #3366CC;">&quot;searchCollection&quot;</span>: <span style="color: #66cc66;">&#91;</span>
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
     <span style="color: #66cc66;">&#93;</span>,
     <span style="color: #3366CC;">&quot;headerText&quot;</span>: <span style="color: #3366CC;">&quot;SearchBox Footer Text&quot;</span>
 <span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>While I have excellent unix-based hosting, I unfortunately don't have an external IIS server that I can publish this out. </p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Article on Zend View Helpers</title>
		<link>http://lebensold.net/development/article-on-zend-view-helpers</link>
		<comments>http://lebensold.net/development/article-on-zend-view-helpers#comments</comments>
		<pubDate>Fri, 01 Feb 2008 08:58:42 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/uncategorized/article-on-zend-view-helpers</guid>
		<description><![CDATA[Another article has been posted on KillerPHP. This one is about Zend View_Helpers. I've been struggling with a good Zend Framework architecture that provides a development roadmap where controller logic can be easily refactored into AJAX controls. At work I've been researching web services for AJAX integration on the ASP.NET tip of things due to [...]]]></description>
			<content:encoded><![CDATA[<p>Another <a href="http://www.killerphp.com/articles/zend-framework-view-helpers/">article has been posted on KillerPHP</a>. This one is about Zend View_Helpers. I've been struggling with a good Zend Framework architecture that provides a development roadmap where controller logic can be easily refactored into AJAX controls. At work I've been researching web services for AJAX integration on the ASP.NET tip of things due to the lack of user-control support for AJAX.NET controls. I'm also not very impressed with the AJAX.NET Extenders since they seem to mix data that would be gathered from a web service and its presentation on the client.</p>
<p><span id="more-55"></span></p>
<p>This has lead me to thinking about AJAX as a two-tier model.</p>
<li><b>Using AJAX calls to render full XHTML (this is like partial templating seen in ruby on rails)</b></li>
<p>This approach is very appealing from a development perspective since you can essentially develop a partial template, render it (using Zend_View if you're working in PHP) and send it down the pipe to the AJAX caller.</p>
<li><b>Using AJAX calls to recieve data from a web service for parsing / manipulation on the client rendered partial.</b></li>
<p>Usually there's an intermediate step on the client before display, whether it means parsing JSON / XML into XHTML or applying a fancy effect. </p>
<p>I think the latter approach will win out as a best practice since it lends itself to greater flexibility on the client side. With the push towards Service-Oriented Architectures, AJAX calls to webservices make more sense than simply relying on pre-built templates. Lastly, the jump from XML to XHTML isn't huge on a client-side and with rich javascript frameworks, parsing JSON and XML is a given.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/article-on-zend-view-helpers/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
