<?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>existdissolve.com</title>
	<atom:link href="http://existdissolve.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://existdissolve.com</link>
	<description>the singularity of being and nothingness</description>
	<lastBuildDate>Wed, 16 May 2012 12:54:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Gloss Updated with ColdFusion 10 Documentation</title>
		<link>http://existdissolve.com/2012/05/gloss-updated-with-coldfusion-10-documentation/</link>
		<comments>http://existdissolve.com/2012/05/gloss-updated-with-coldfusion-10-documentation/#comments</comments>
		<pubDate>Wed, 16 May 2012 12:54:03 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ColdFusion 10]]></category>
		<category><![CDATA[Gloss]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2413</guid>
		<description><![CDATA[On the heels of yesterdays&#8217;s official release of ColdFusion 10, I&#8217;ve updated Gloss with support for both ColdFusion 10 AND ColdFusion 9 reference guides. Enjoy!]]></description>
			<content:encoded><![CDATA[<p>On the heels of <a href="http://blogs.coldfusion.com/post.cfm/adobe-coldfusion-10-is-now-available">yesterdays&#8217;s official release of ColdFusion 10</a>, I&#8217;ve updated <a href="http://cfgloss.com/">Gloss</a> with support for both ColdFusion 10 AND ColdFusion 9 reference guides.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/05/gloss-updated-with-coldfusion-10-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColdFusion Bug? EntityToQuery() and Unknown Data Type</title>
		<link>http://existdissolve.com/2012/05/coldfusion-bug-entitytoquery-and-unknown-data-type/</link>
		<comments>http://existdissolve.com/2012/05/coldfusion-bug-entitytoquery-and-unknown-data-type/#comments</comments>
		<pubDate>Thu, 03 May 2012 04:10:37 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[EntityToQuery]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2408</guid>
		<description><![CDATA[I ran into an interesting issue today. To make a long story a little less uninteresting, I was basically trying to go from an array of ORM entities to an Excel dump of the data in those entities. Obviously, the easiest way to accomplish this is to first convert the array of entities to a&#8230;]]></description>
			<content:encoded><![CDATA[<p>I ran into an interesting issue today. To make a long story a little less uninteresting, I was basically trying to go from an array of ORM entities to an Excel dump of the data in those entities. Obviously, the easiest way to accomplish this is to first convert the array of entities to a query, and then pass the query result set off to the built-in CF Excel manipulation functions.</p>
<p>Easy enough. With one little line of code, you can very simply convert ORM entities to a ColdFusion query&#8230;just like so:</p>
<pre>// get the orm entities
ormstuff = <strong>EntityLoad</strong>( "Art" );
// convert the orm goodness to a CF query
anicequery = <strong>EntityToQuery</strong>( ormstuff );</pre>
<p>Cake, right? If I were to hand this query off to CF&#8217;s spreadsheet functions, I could easily prepare and export a nice Excel file full of the data I just converted. But of course, nothing is that simple&#8230;and that&#8217;s where the potential bug announced itself.</p>
<h2>A Dark Foreboding</h2>
<p>You see, instead of simply dumping all the data for all the columns of the query-which-was-once-an-entity, I wanted to pare down the list of columns that would be output in the Excel export. Since I already had a query handy, I figured passing a list of column names to a Query-of-Queries would make short work of this. However, the moment I tried this&#8230;</p>
<p><strong>BOOM!</strong></p>
<p>I received the following error:</p>
<blockquote><p>Query Of Queries runtime error. Unsupported SQL type java.sql.Types.UNKNOWN</p></blockquote>
<h2>The Weirdness Begins</h2>
<p>So what happened? Turns out that one of my columns (a BIT column on the database) was being converted to an &#8220;UNKNOWN&#8221; data type in the query result. You can see this easily by viewing the metadata of the query object (notice the &#8220;ISSOLD&#8221; column):</p>
<pre>writedump( <strong>getMetaData</strong>( anicequery ) );</pre>
<p><a href="http://existdissolve.com/wp-content/uploads/2012/05/dump.png"><img class="alignleft size-full wp-image-2409" title="dump" src="http://existdissolve.com/wp-content/uploads/2012/05/dump.png" alt="" width="164" height="296" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>The Weirdness Grows</h2>
<p>As strange as this is, it gets weirder.</p>
<ul>
<li>If I do a non-entity query of the database and the dump the result, the data type for &#8220;ISSOLD&#8221; is not UNKNOWN, but the correct data type.</li>
<li>If I pass a &#8220;*&#8221; in the Q-of-Q instead of a list containing the offending column&#8217;s name, no error occurs</li>
<li>CAST() the column, you say? Yep, tried that. No dice.</li>
<li>Changing the &#8220;type&#8221; and &#8220;ormtype&#8221; attributes of the BIT column&#8217;s properties in the ORM mapping don&#8217;t help. I tried a number of combinations, but could not get the &#8220;TypeName&#8221; to ever NOT be &#8220;UNKNOWN&#8221;</li>
<ul>
<li>Ok, that&#8217;s not 100% true. if I leave those attributes off, the TypeName is set to &#8220;JAVA_OBJECT&#8221;, and the QofQ is able to execute without error. Of course, <em><strong>this is only for MySQL</strong></em>&#8230;in SQL Server, I couldn&#8217;t get it to change, even with the same settings as what &#8220;worked&#8221; for MySQL. Ugh.</li>
</ul>
</ul>
<h2>The Weirdness Ends</h2>
<p>After several unfruitful experiments and dozens of minutes Googling to no avail, I put an end to the madness by simply writing my own version of <strong>EntitytoQuery()</strong>. It&#8217;s ugly and still a work in progress, but it at least by-passes the issue I encountered.</p>
<blockquote><p>If you&#8217;re interested in seeing this issue in action, check out the demo pages I put up (each page has a dump of the code for the entities):</p>
<ul>
<li><a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/orm/sqlorm/">SQL Server 2008</a></li>
<li><a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/orm/mysqldump.cfm">MySQL</a></li>
</ul>
<p><span style="line-height: 20px;">I&#8217;ve also <a href="https://bugbase.adobe.com/index.cfm?event=bug&amp;id=3180344">submitted a bug for this</a>, so if you think it&#8217;s crazy, feel free to vote!</span></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/05/coldfusion-bug-entitytoquery-and-unknown-data-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ColdFusion Bug: SerializeJSON() and ORM Entities</title>
		<link>http://existdissolve.com/2012/04/coldfusion-bug-serializejson-and-orm-entities/</link>
		<comments>http://existdissolve.com/2012/04/coldfusion-bug-serializejson-and-orm-entities/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:13:57 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Dump]]></category>
		<category><![CDATA[SerializeJSON]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2405</guid>
		<description><![CDATA[Recently, I&#8217;ve been messing around quite a bit with ORM in ColdFusion. I really like the benefits that it brings to developing applications. However, I noticed a very big bug yesterday while attempting to user serializeJSON() on a an entity using a one-to-many relationship. Some Context Let&#8217;s say that you have two entities that are related&#8230;]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve been messing around quite a bit with ORM in ColdFusion. I really like the benefits that it brings to developing applications. However, I noticed a very big bug yesterday while attempting to user serializeJSON() on a an entity using a one-to-many relationship.</p>
<h2>Some Context</h2>
<p>Let&#8217;s say that you have two entities that are related via a one-to-many relationship (Artists and Art, for example). You can easily create this relationship in your model by doing something like the following:</p>
<pre>property name="art" fieldtype="one-to-many" fkcolumn="artistid" cfc="Art" remotingfetch="true";</pre>
<p>If we were to dump the result of an EntityLoad() of &#8220;Artists&#8221;, we&#8217;d see a nice structured relationship: First, an array of all Artist entities, and then an array of all Art entities related to the particular ArtistID. Additionally, I&#8217;ve specified remotingfetch=true, which will force CF to load the Art entities for each Artist.</p>
<h2>The Bug</h2>
<p>The bug, however, comes into play when you try to serialize the result of EntityLoad(). While it properly composes the relationships, it represents the first two entities in the &#8220;art&#8221; array; any subsequent entities in the given array are returned simply as &#8220;{}&#8221;.  Whether you have 3 &#8220;Art&#8221; entities for an artists, or 20, only the first 2 will ever be serialized properly.</p>
<blockquote><p>See this happening in CF10:</p>
<ul>
<li>Regular, correct composition of entities via straight CFDUMP &#8211; <a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/orm/dump.cfm">LINK</a></li>
<li>&#8220;First two&#8221; problem via dump of serializeJSON() &#8211; <a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/orm/">LINK</a></li>
</ul>
</blockquote>
<h2>It Gets Worse</h2>
<p>The worst part about this is that it is a relatively old bug. It was <a href="https://bugbase.adobe.com/index.cfm?event=bug&amp;id=3042650">first submitted </a>for CF9 back in October 2010, was deferred, and was <a href="https://bugbase.adobe.com/index.cfm?event=bug&amp;id=3175667">apparently not fixed</a> for the public beta of CF10.</p>
<p>I think this is a huge issue, and should be a priority to be fixed. Until it is (or a suitable workaround is devised), it will be incredibly difficult to create applications of any complexity that depend upon serialization of entities.</p>
<h2>Vote, Vote, Vote</h2>
<p>The best way to get it fixed, of course, is to make your voice heard and vote up the bug. Here are some links for that:</p>
<p><strong>Bug Report &#8211; CF 9: </strong>https://bugbase.adobe.com/index.cfm?event=bug&amp;id=3042650</p>
<p><strong>Bug Report &#8211; CF 10:</strong> https://bugbase.adobe.com/index.cfm?event=bug&amp;id=3175667</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/04/coldfusion-bug-serializejson-and-orm-entities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExtJS 4: Applying Model Validations to Forms</title>
		<link>http://existdissolve.com/2012/04/extjs-4-applying-model-validations-to-forms/</link>
		<comments>http://existdissolve.com/2012/04/extjs-4-applying-model-validations-to-forms/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 12:28:49 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Model Validations]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2398</guid>
		<description><![CDATA[One of my absolute favorite things about ExtJS&#8217; data model is how simple it is to apply a Model instance to a form. If you&#8217;ve never done this before, consider the following data model: Ext.define('Validations.model.Person', {     extend: 'Ext.data.Model',     fields: [         {name:"name", type:'string'},         {name:"age",&#8230;]]></description>
			<content:encoded><![CDATA[<p>One of my absolute favorite things about <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model">ExtJS&#8217; data model</a> is how simple it is to apply a Model instance to a form. If you&#8217;ve never done this before, consider the following data model:</p>
<pre>Ext.define('Validations.model.Person', {
    extend: 'Ext.data.Model',
    fields: [
        {name:"name", type:'string'},
        {name:"age", type:"int"},
        {name:"hobby", type:"string"}
    ]
})</pre>
<p>Also, assume we have a form defined like so:</p>
<pre>Ext.define('Validations.view.people.Form', {
    extend: 'Ext.form.Panel',
    alias: 'widget.peopleform',
    bodyPadding: 10,
    border: false,
    initComponent: function() {
        var me = this;
        Ext.applyIf(me, {
            defaults: {
                width: 250,
                labelWidth: 70
            },
            items: [
                {
                    xtype: 'textfield',
                    name: 'name',
                    id: 'name',
                    fieldLabel: 'Name'
                },
                {
                    xtype: 'numberfield',
                    name: 'age',
                    id: 'age',
                    fieldLabel: 'Age',
                    value: 20
                },
                {
                    xtype: 'textfield',
                    name: 'hobby',
                    id: 'hobby',
                    fieldLabel: 'Hobby'
                }
            ]
        });
        me.callParent(arguments);
    }
})</pre>
<p><strong>NOTE:</strong> Notice that the &#8220;name&#8221; properties of each form field maps 1:1 with the &#8220;name&#8221; properties in my Model.</p>
<p>Now, let&#8217;s say that we want to edit a Model instance. We could, of course, manually set the value of each form field to that of the corresponding field in the Model. However, this is clunky and unnecessary, given that the form itself has a method for doing this automatically. Consider the following:</p>
<pre>// get first model instance in store
 myrecord = somestore.getAt(0)
 // load form with data from selected model instance
 myform.loadRecord(myrecord)</pre>
<p>Pretty simple, right? When calling the <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-loadRecord">loadRecord()</a> method on the form, any field in the form whose name value matches the name definition in the specified Model will be loaded with the data of that particular field.</p>
<blockquote><p>Try it out. Open the demo, and double-click on any record in the grid. On the itemdblclick event of the grid, the form&#8217;s loadRecord() method is invoked, and the Model data corresponding to the clicked row in the grid is applied to the form&#8217;s fields</p></blockquote>
<h2>Validation, Validation, Validation</h2>
<p>So that&#8217;s pretty easy. But of course, when dealing with data&#8211;whether on the Model or in a form&#8211;you&#8217;re going to want to validate it to make sure that you have the data you&#8217;re expecting, and that the data is in the right format.</p>
<p>In ExtJS, there are a few different ways you can validate Model data.</p>
<p><strong>First</strong>, you can apply validations directly to the model itself. For example, let&#8217;s add in a few to the Model already setup:</p>
<pre>Ext.define('Validations.model.Person', {
    extend: 'Ext.data.Model',
    fields: [
        {name:"name", type:'string'},
        {name:"age", type:"int"},
        {name:"hobby", type:"string"}
    ],
    ,
    validations: [
        {type: 'presence', field: 'name', message: 'You have to enter a name, silly'},
        {type: 'presence', field: 'age', message: 'You must specify an age'},
        {type: 'presence', field: 'hobby', message: 'You must enter a hobby'},
        {type: 'length', field: 'hobby', min:5, message: 'You must specify a hobby with more than 4 characters'}
    ]
})</pre>
<p>In this example, I&#8217;ve applied a &#8220;presence&#8221; validation to each field, which requires that each field has a value, as well as a &#8220;length&#8221; validation to the &#8220;hobby&#8221; field. When calling the Model&#8217;s validate() method, the instance&#8217;s current data will be run through the validations.</p>
<p>The second, albeit indirect, way to validate the Model is to apply validations to the form fields themselves, such as defining properties like <strong>allowBlank</strong> (e.g., &#8220;presence&#8221;), specifying a custom <strong>vType</strong> for the field, using a regex, etc.</p>
<p>While both of these approaches are great, they are not particularly related. For example, if we have NO validations whatsoever on the form, we could submit perfectly valid Form data, but this data may yet trigger validations when the Model is validated. By default, the form doesn&#8217;t care about the Model-level validations, and will only trigger Form-level validations that have been defined.</p>
<h2>Applying Model Validation to Form Fields</h2>
<p>While this disconnect is certainly understandable, I thought it would be cool if both validations could be supported when the form is being validated. Here&#8217;s a short list of my requirements:</p>
<ul>
<li>Model validations should be enforced at a field by field level (e.g., if there are two validations for &#8220;name&#8221;, these should both be enforced on the &#8220;name&#8221; field in the form)</li>
<li>Both Model and Form field validations should be respected</li>
<li>Both Model and Form field validations should be communicated to the user</li>
</ul>
<p>So how to do this? While there are probably a dozen ways to accomplish this goal, the approach I took was to simply override <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic">Ext.form.Basic</a> and <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Base">Ext.form.field.Base</a>.</p>
<p>The first step is to make the form aware of Model validations. Since we really only care about this when the Model data is loaded to the form via <strong>loadRecord()</strong>, we can start by overriding this method like so:</p>
<pre>Ext.override(Ext.form.Basic, {
    loadRecord: function(record) {
        this._record = record;
        <strong>this.setModelValidations(record.validations);</strong>
        return this.setValues(record.data);
    },
    setModelValidations: function(validations) {
        var fields = this.getFields(), i;
        for(i=0;i&lt;validations.length;i++) {
            if(fields.map[validations[i].field]) {
                fields.map[validations[i].field].setModelFieldValidation(validations[i])
            }
        }
    }
})</pre>
<p>When loadRecord() is invoked, we pass the record to a new custom method, setModelValidations(). This custom method will iterate over the <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.validations">validations object</a> of the specified Model, and will invoke the setModelFieldValidation() method of any form field it finds whose mapping matches that of the Model validation.</p>
<p>The next override is on the base definition for form fields, and looks like so:</p>
<pre>Ext.override(Ext.form.field.Base, {
    setModelFieldValidation: function(validation) {
        this.modelValidations = Ext.isArray(this.modelValidations) ? this.modelValidations : [];
        this.modelValidations.push(validation);
    },
    getModelErrors: function(value) {
        var errors      = Ext.create('Ext.data.Errors'),
            validations = this.modelValidations,
            validators  = Ext.data.validations,
            length, validation, field, valid, type, i;

        if (validations) {
            length = validations.length;

            for (i = 0; i &lt; length; i++) {
                validation = validations[i];
                field = validation.field || validation.name;
                type  = validation.type;
                valid = validators[type](validation, value);

                if (!valid) {
                    errors.add({
                        field  : field,
                        message: validation.message || validators[type + 'Message']
                    });
                }
            }
        }
        return errors;
    },
    validateValue: function(value) {
        var me = this,
            errors = me.getErrors(value),
            modelErrors = me.getModelErrors(value),
            isValid = Ext.isEmpty(errors) <strong>&amp;&amp; modelErrors.isValid()</strong>;
        if (!me.preventMark) {
            if (isValid) {
                me.clearInvalid();
            }
            else {
                <strong>if(!modelErrors.isValid()) { modelErrors.each(function() { errors.push(this.message); }) }</strong>
                me.markInvalid(errors);
            }
        }
        return isValid;
    }
})</pre>
<p>There&#8217;s a lot going on here, so let&#8217;s go method by method.</p>
<p><strong>setModelFieldValidation()</strong>: This is method that is called from the Form&#8217;s setModelValidations() method, and it simply adds a new property to the instance of the form field (modelValidations). This modelValidations is an array which will store any Model-level validations which have been configured for the Model field which matches this form field&#8217;s &#8220;name&#8221;.</p>
<p><strong>getModelErrors()</strong>: This method is almost identical to the Model&#8217;s getErrors() method. The primary difference is that instead of iterating over every validation defined for the Model, this method only iterates over the Model validations which have been assigned to this form field (via setModelFieldValidations()).</p>
<p><strong>validateValue()</strong>: This is an override of the field&#8217;s existing validateValue() method, which is invoked everything a validation occurs. The only additions are to add the Model validation to the check for whether the form &#8220;isValid&#8221;, as well as a short section to append the model validation error messages to the main &#8220;errors&#8221; array (which is ultimately used for communicating the form&#8217;s validation errors to the user).</p>
<h2>Demo and Source</h2>
<p>If you&#8217;d like to see this in action, <a href="http://existdissolve.com/demos/validations/">check out the demo</a>. If you&#8217;d like to see the full source for this mini-app, <a href="https://github.com/existdissolve/ExtJS.4.Playground/tree/master/playground/validations">grab it from GitHub</a>.</p>
<h2>Wrapping Up</h2>
<p>In all honesty, I&#8217;m not sure how practical this approach actually is, or whether you&#8217;d actually want to forge this relationship between the form and model validations. But regardless of the practicality, I think it does, at the very least, demonstrate precisely how stupid simple it is to extend ExtJS to do pretty much whatever you want it to do. And notwithstanding the usefulness of this particular example, this extensibility is precisely why I love this framework.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/04/extjs-4-applying-model-validations-to-forms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick Thoughts on Sencha Architect 2</title>
		<link>http://existdissolve.com/2012/04/quick-thoughts-on-sencha-architect-2/</link>
		<comments>http://existdissolve.com/2012/04/quick-thoughts-on-sencha-architect-2/#comments</comments>
		<pubDate>Sat, 21 Apr 2012 03:11:42 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Sencha Touch]]></category>
		<category><![CDATA[Architect 2]]></category>
		<category><![CDATA[Sencha]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2395</guid>
		<description><![CDATA[A few days ago, Sencha rolled out Sencha Architect 2, the major overhaul and rebranding of what was formerly Sencha Designer. You can check out the release blog post to get the low-down on all the new features. When I saw the news about the release, I have to say I was a bit hesitant&#8230;]]></description>
			<content:encoded><![CDATA[<p>A few days ago, Sencha rolled out <a href="http://www.sencha.com/products/architect/">Sencha Architect 2</a>, the major overhaul and rebranding of what was formerly Sencha Designer. You can check out the <a href="http://www.sencha.com/blog/sencha-architect-html5-app-builder-for-touch-and-ext-js/">release blog post</a> to get the low-down on all the new features.</p>
<p>When I saw the news about the release, I have to say I was a bit hesitant to look much further. I&#8217;ve tried Sencha Designer several times in the past, and I&#8217;ve been somewhat disappointed with it. Sure, it was great for laying out apps, but when you actually needed to *code*, it was lackluster at best. But even worse, I found it to be very buggy; it would crash at random times, and overall I found the process of trying to mockup an app to be more frustrating than anything else.</p>
<p>So initially, I wasn&#8217;t planning on even trying out the newest iteration. But then I noticed that one of the biggest additions to the product is  support for creating a full ExtJS or Touch app&#8211;not just the UI. I felt I had to take a closer look, and I&#8217;m glad I did.</p>
<h2>UI</h2>
<p>Out of the box, Architect 2 is <em><strong>worlds better</strong></em> than its previous iterations. The interface is slick and responsive, and the way the UI is organized makes the process of laying out and configuring components feel much more intuitive. One especially nice feature is that in the &#8220;Property&#8221; panel, you can toggle between commonly used configurations and the comprehensive list. Additionally, the configuration options are nicely grouped by inheritance, so you know precisely where your configs are being applied.</p>
<h2>Application Flow</h2>
<p>The coolest part of Architect 2 (to me) is that you can now *really* build applications with it. If you drink the MVC architecture Kool-Aid (and you should!), Architect 2 makes it very simple to build full-on applications.</p>
<p>For example, you can very simply choose to add controllers to your app. Within the controllers, you can customize handlers and custom methods to take care of the all of the business logic of your application.</p>
<h2>Best Practices</h2>
<p>But perhaps the best part of Architect 2 is that in the course of adding components, wiring up event handlers, and just fleshing out your app, you can instantly switch to &#8220;Code&#8221; view to see how the entire app is getting constructed behind the scenes. This gives a much welcome insight into &#8220;best practices&#8221; for developing ExtJS and Touch apps within the MVC architecture&#8211;a much desired feature that many devs have been begging for for quite a while.</p>
<p>I was happy to see that my methodology that was about 95% on point; however, the differences that I&#8217;ve noticed while reviewing the code have filled in some gaps in my understanding, which will simply make building ExtJS and Touch apps that much more fun <img src='http://existdissolve.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>So&#8230;Will I Buy It?</h2>
<p>At $399, the price tag for Sencha Architect 2 initially feels a little steep. Personally, I would not have paid that much for previous versions, purely based on my lackluster experiences during the trials. However, given how much more solid Architect 2 feels, and based on the fact that it is now geared toward full soup-to-nuts app development, I&#8217;ll have to seriously consider it.</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/04/quick-thoughts-on-sencha-architect-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Diversion: Making Nested Arrays from Query Data</title>
		<link>http://existdissolve.com/2012/03/php-diversion-making-nested-arrays-from-query-data/</link>
		<comments>http://existdissolve.com/2012/03/php-diversion-making-nested-arrays-from-query-data/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 03:49:59 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Nested Data]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2386</guid>
		<description><![CDATA[As if the title doesn&#8217;t give away the whole plot, I&#8217;m currently working on a project that uses PHP&#8211;gasp! No, I&#8217;ve not abandoned ColdFusion, and too be completely honest, I&#8217;m kind of a PHP noob. Sure, I can do a fair amount of things in PHP&#8230;you know, querying databases, echoing content, that kind of stuff.&#8230;]]></description>
			<content:encoded><![CDATA[<p>As if the title doesn&#8217;t give away the whole plot, I&#8217;m currently working on a project that uses PHP&#8211;gasp! No, I&#8217;ve not abandoned ColdFusion, and too be completely honest, I&#8217;m kind of a PHP noob.</p>
<p>Sure, I can do a fair amount of things in PHP&#8230;you know, querying databases, echoing content, that kind of stuff. Where I really get hurt, though, is when things start to get complex.</p>
<blockquote><p>NOTE: If you don&#8217;t particularly feel like reading and just want to see some code, be sure to <strong><a href="https://github.com/existdissolve/MakeNestedArrayForJSON">check out my GitHub repo</a></strong> for this.</p></blockquote>
<h2>Some Context</h2>
<p>For example, I recently needed to build out an <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.view.View">ExtJS View</a>, and I wanted to have some pretty heavily-nested data. My ideal outcome would print something to the page like so:</p>
<pre>Main Group 1
   Category 1
      Name 1
      Name 2
         Fav Color 1
         Fav Color 2
Main Group 2
   Category 1
      Name 1
      Name 2
Main Group 3
   Category 2
      Name 1
   Category 3
      Name 1</pre>
<p>And so on. In other words, each step in the &#8220;tree&#8221; can have multiple children, which can themselves have multiple children, <em>ad infinitum</em>.</p>
<p>Now in ExtJS, creating a View is dead simple. You simply have to pass the View a JSON structure wherein each level is an array of objects. My problem, however, was not with the ExtJS side. Rather, it was turning a MySQL query result set into a structure that could be serialized into the proper format and sent off to ExtJS.</p>
<h2>An Initial Attempt</h2>
<p>Unfortunately, there is nothing in PHP like <a href="http://cfgloss.com/#1:WSc3ff6d0ea77859461172e0811cbec22c24-7ff6.html">ColdFusion&#8217;s amazing &#8220;group&#8221; attribute in the &lt;cfoutput&gt; tag</a>. So not knowing what to do, I headed out to The Google, and asked it to tell me about &#8220;creating nested json&#8221; and &#8220;nested data&#8221; and the like. For the most part, the answers I found suggested doing something like this:</p>
<ul>
<li>Set a &#8220;flag&#8221; for the group (this will be updated when you move to a different group)</li>
<li>Loop over record set. When you reach a new &#8220;group&#8221; (e.g., group value != flag), reset the group flag, create a new array for the group data, nest child data, etc.</li>
</ul>
<p>While this approach certainly works (I used it in my first several *attempts*), it gets hairy really quickly. Sure, it&#8217;s not a huge deal when you have a simple &#8220;group&#8221; -&gt; &#8220;item&#8221; relationship. However, when you have to start nesting data in more complex fashions, it becomes incredibly unwieldy. Not only is it unsustainable as you have to replicate the functionality for EVERY change in data, but it&#8217;s also a nightmare because there are only so many &#8220;flags&#8221; and &#8220;nested flags&#8221; that the human brain can keep track of at a single time.</p>
<h2>A Better Approach&#8230;But Still Not Great</h2>
<p>I quickly abandoned this process. it was a headache to write, and the thought of having to do it <em>N</em> times for each query was maddening. So I stepped back a bit, and tried to think a bit more critically about my approach. One big problem, in my estimation, is that I was getting tripped up by the conversion from the flat result set from MySQL to the nested-array model I needed. The flags became a mess really quickly, because they were each trying to keep track of their place within the whole data set, instead of a &#8220;parent&#8221; only being concerned about whatever children it might have.</p>
<p>With this in mind, my second approach took the form of trying to iteratively reduce the data being dealt with at any particular &#8220;level&#8221; of the process. My first step was to create a quick function to transform the result set from MySQL into a super-dumb array.</p>
<pre>function convertquerytoarray($query) {
   while($row = mysql_fetch_assoc($query)) {
      $rows[] = $row;
   }
   return $rows;
}</pre>
<p>With this done, I proceeded to leverage <a href="http://php.net/manual/en/control-structures.foreach.php">PHP&#8217;s foreach()</a> to loop over each record:</p>
<pre>$gidx = '';
$groups = array();
$allrows = convertquerytoarray($sqlresult);
foreach($allrows as $row) {
   if($row['group'] != $gidx) {
      $carr = filterarraybykey($allrows,'group',$row['group']);
      ...
   }
}</pre>
<p>Now you&#8217;ll notice that in the midst of the &#8220;group&#8221; foreach() loop, I create a new array ($carr) and assign to it the value returned from the <strong>filterarraybykey()</strong> method. Here&#8217;s what that looks like:</p>
<pre>function filterarraybykey($array,$key,$val) {
   return array_filter($array,function($row) use($key,$val) {
      return $val==$row[$key];
   });
}</pre>
<p>As I mentioned, the idea here is that for each &#8220;parent&#8221;, evaluating the children (and children&#8217;s children) would seem to be much easier if we limit down the data being evaluated within that relationship to only that data which is contained within the relationship.</p>
<p>So, let&#8217;s say that we have 3 groups: &#8220;Cats, Dogs, Hamsters&#8221;. When the &#8220;Cats&#8221; group is being evaluated, the <strong>filterarraybykey()</strong> method will take the full result set ($allrows), and return an array that has only the values that have a &#8220;group&#8221; value of &#8220;Cats&#8221;&#8230;maybe 5 records instead of the whole 20 of the full result set.</p>
<p>Now that I&#8217;ve limited the result set, I can continue the pattern farther down, applying the same technique to &#8220;categories&#8221; and &#8220;names&#8221;:</p>
<pre>$gidx = '';
$groups = array();
$allrows = convertquerytoarray($sqlresult);
foreach($allrows as $row) {
   if($row['group'] != $gidx) {
      $carr = filterarraybykey($allrows,'group',$row['group']);
      $cidx = '';
      $categories = array();
      foreach($carr as $row) {
         if($row['category'] != $cidx) {
            $narr = filterarraybykey($carr,'category',$row['category']);
            $nidx = '';
            $names = array();
            foreach($narr as $row) {
               if($row['name'] != $nidx) {
                  $name = array('name'=&gt;row['name'];
                  array_push($names,$name);
                  $nidx = $row['name'];
               }
            }
            $category = array('category'=&gt;$row['category'],'names'=&gt;$names);
            array_push($categories,$category);
            $cidx = $row['category'];
          }
      };
      $group = array('group'=&gt;$row['group'],'categories'=&gt;$categories);
      array_push($groups,$group);
      $idx = $row['group'];
   }
}</pre>
<p>Alright, this feels a little better. Even though it still has a bunch of &#8220;flags,&#8221; the logic is pretty easy to follow. Since the result set being evaluated at each &#8220;level&#8221; of the nesting is constantly getting whittled, it eases the burden of trying to figure out where the particular record exists within the WHOLE data set. In this approach, you only have to worry about the current parent and siblings. Plus, since we have nested foreach() loops, each &#8220;level&#8221; is more or less self-contained.</p>
<p>Although this is a bit better, it still suffers from many of the same issues as the first. Namely, every time this needs to be changed, or every time I need something like this elsewhere (perhaps a grouping of only groups and names, with no categories), I have to recreate this nesting nightmare. If at any point along the way my flags or row pointers get off (via typo, omission, etc.), things will break, and frustration will ensue.</p>
<h2>A Final (Hopefully Better) Solution</h2>
<p>So while the last approach is still kind of kludgy, I think it&#8217;s moving in the right direction. Since each &#8220;level&#8221; of nesting represents a thin, relationally isolated slice of the total data set, it&#8217;s easier to drop things in and out of it to get the results you want. Therefore, with this as a basis, my last shot at a solution was an attempt to abstract the philosophy of this approach. I&#8217;ll paste the whole example, and then explain what&#8217;s going on:</p>
<pre>function makenestedarray($array,$model) {
   // check if array is a mysql result; if so, convert it to a flat array
   $array = gettype($array)=='resource' ? convertquerytoarray($array) : $array;
   // set blank index for tracking which rows we've already added
   $idx = '';
   // blank array to store all the data
   $master = array();
   // retrieve value of "key" for the current iteratin of the data model
   $key = $model['key'];
   // loop over each row in the passed data array
   foreach($array as $row) {
      // if the value is not equal to the index value, evaluate row
      if($row[$key] != $idx) {
         // retrieve data for row based on model definition
         $item = makerowdata($row,$model);
         // if current level has "children" defined, evaluate each child
         if(isset($model['children'])) {
            // loop over array of children
            foreach($model['children'] as $child=&gt;$val) {
            // whittle it down based on the child's data key
               $childarr = filterarraybykey($array,$key,$row[$key]);
               // recursively call makenestedarray()
               $children = makenestedarray($childarr,$val);
               // add nested data to parent array
               $item[$child]=$children;
            }
         }
         // done with all the looping; add current data item to master array
         array_push($master,$item);
         // update the index and kip rows if they have the same index
         $idx = $row[$key];
      }
   }
   // yay! all finished; return the completed data object
   return $master;
}

function makerowdata($row,$struct) {
   $columns = array();
   $keys = array_keys($struct);
   foreach($keys as $pos=&gt;$key) {
      if($key != 'key' &amp;&amp; $key != 'children') {
         $columns[$struct[$key]] = $row[$key];
      }
   }
   return $columns;
}

$model = array(
   'key'=&gt;'group',
   'group'=&gt;'group',
   'groupid'=&gt;'id',
   'children'=&gt;array(
      'categories'=&gt;array(
      'key'=&gt;'category',
      'category'=&gt;'category',
      'children'=&gt;array(
         'names'=&gt;array(
            'key'=&gt;'names',
            'nameid'=&gt;'id',
            'name'=&gt;'name'
         )
      )
   )
);
$data = makenestedarray($sqlresult,$model);
$returnjson = array("groups" =&gt; $data);
// serialize this mug, and return the string
return json_encode($returnjson);</pre>
<p>My solution involves creating a recursive method to do what the last approach did&#8211;whittle down the data set being evaluated as the &#8220;level&#8221; increases. The big difference, of course, is that the recursive method couldn&#8217;t care less what the data being thrown at it is, and doesn&#8217;t particularly care how many levels of nesting there might be.</p>
<p>And this is what I like about this approach. Instead of manually looping and nesting data, all I have to do is define a &#8220;model&#8221; of the data in the form I&#8217;d like it be prepared, and the recursive <strong>makenestedarray()</strong> will do the rest.</p>
<p>This has a couple big benefits.</p>
<p><strong>First,</strong> if I need to create various nested data arrays for ExtJS of different configurations (and I definitely do), I no longer have to worry about the headache of creating the nested nightmares of the first two &#8220;solutions.&#8221; I simply plot out exactly the data model that I want to return, and the method takes care of it for me.</p>
<p>And <strong>second</strong>, the &#8220;model&#8221; provides a nice visual verification of how the data I&#8217;m preparing is going to look when it&#8217;s returned as JSON. And if I need to make a quick tweak (like adding an additional data column to be returned at some level within this structure), it&#8217;s easy to add as I only need to update the model, and not the mechanism creating the ultimate output.</p>
<h2>Wrapping Up</h2>
<p>So what are your thoughts? This is the result of a lot of pain, headaches, and trial and error. Since I&#8217;m a total PHP noob, I acknowledge that it&#8217;s entirely possible (if not probable) that there are much cleaner, easier, and elegant solutions to this seemingly routine need. However, I wanted to write this up, if for nothing else than for my own benefit of reminiscing about the process I went through to get from absolute frustration to a sustainable solution that I feel pretty happy about.</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/03/php-diversion-making-nested-arrays-from-query-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ColdFusion 10 Beta Examples are Live</title>
		<link>http://existdissolve.com/2012/02/coldfusion-10-beta-examples-are-live/</link>
		<comments>http://existdissolve.com/2012/02/coldfusion-10-beta-examples-are-live/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 13:26:18 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ColdFusion 10 Beta]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2383</guid>
		<description><![CDATA[I recently created a free ColdFusion 10 Beta hosting account with Hostek.com. It&#8217;s pretty awesome, so you should create one too! Anyway, with that in place, I&#8217;ve uploaded my examples of ArrayEach(), StructEach(), and ArrayFilter(). I&#8217;ve also put them out on GitHub, so feel free to take a look if it suits you. Enjoy!]]></description>
			<content:encoded><![CDATA[<p>I recently created a <strong><a href="https://cp.hostek.com/cart.php?a=confproduct&amp;i=0">free ColdFusion 10 Beta hosting account</a></strong> with Hostek.com. It&#8217;s pretty awesome, so you should create one too!</p>
<p>Anyway, with that in place, I&#8217;ve uploaded my examples of <a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/each/array.cfm">ArrayEach()</a>, <a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/each/struct.cfm">StructEach()</a>, and <a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/filter/">ArrayFilter().</a> I&#8217;ve also <a href="https://github.com/existdissolve/CF10">put them out on GitHub</a>, so feel free to take a look if it suits you.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/02/coldfusion-10-beta-examples-are-live/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ColdFusion 10: Filter Functions</title>
		<link>http://existdissolve.com/2012/02/coldfusion-10-filter-functions/</link>
		<comments>http://existdissolve.com/2012/02/coldfusion-10-filter-functions/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 04:14:51 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[ArrayFilter]]></category>
		<category><![CDATA[ListFilter()]]></category>
		<category><![CDATA[StructFilter()]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2376</guid>
		<description><![CDATA[In the vein of my last post on ColdFusion 10&#8242;s new ArrayEach() and StructEach() functions, there are some other related functions that help with the very common task of filtering arrays, structs, and list. The new functions are ArrayFilter(), ListFilter(), and StructFilter(). Like ArrayEach() and StructEach(), the new filter methods have a &#8220;function&#8221; parameter (which&#8230;]]></description>
			<content:encoded><![CDATA[<p>In the vein of my <a title="ColdFusion 10: ArrayEach and StructEach, Hooray!" href="http://existdissolve.com/2012/02/coldfusion-10-arrayeach-and-structeach-hooray/">last post on ColdFusion 10&#8242;s new <strong>ArrayEach()</strong> and <strong>StructEach()</strong> functions,</a> there are some other related functions that help with the very common task of filtering arrays, structs, and list. The new functions are <strong>ArrayFilter()</strong>, <strong>ListFilter()</strong>, and <strong>StructFilter()</strong>.</p>
<p>Like <strong>ArrayEach()</strong> and <strong>StructEach()</strong>, the new filter methods have a &#8220;function&#8221; parameter (which can also be either an inline function or a named function). However, unlike <strong>ArrayEach()</strong> and <strong>StructEach()</strong> which return nothing, the new filter functions return a <strong>new</strong> array, list, or struct, respectively.</p>
<p>To accomplish this, you need to return a boolean from the function parameter. If the current array element, list item, or structure value matches some criteria and returns &#8220;true&#8221;, it will be added to the new returned array/list/structure. Conversely, if it fails the criteria and returns &#8220;false,&#8221; it will be excluded from what is returned.</p>
<blockquote><p><strong>NOTE:</strong>  The array/list/struct filter() functions return <strong>NEW</strong> arrays/lists/structures. The original arrays/lists/structs against which the filter() functions are called are unaffected.</p></blockquote>
<h2>An Example</h2>
<p>Let&#8217;s say that we have a simple set of &#8220;circles&#8221; for a <a title="Add Me :)" href="https://plus.google.com/u/0/104753668904759400057" target="_blank">Google+ account</a> which includes a circle for friends, one for co-workers, and another for family. We might model this data like so:</p>
<pre>'circles' = {
    'friends': ['Lucas','Phil','Dave','Brian','Dillon'],
    'coworkers': ['Tyler','Mike','Doug'],
    'family': ['Dean','Jared','Jason']
};</pre>
<p>Now, let&#8217;s imagine that for some reason, we want to filter all of the people in our circles, and return all the contacts (regardless of circle) whose names start with the letter &#8220;D&#8221;.  One approach might be as so:</p>
<pre>// create an array to hold all the names
allDnames = [];
// use structeach() to evaluate each "circle" 
structeach(circles,function(key,value) {
     // "matched" names will be the new array returned from the arrayfilter()
     // which is applied to each circle in the structeach() loop
     matchednames = <strong>arrayfilter</strong>(value,function(obj) {
         // if the first letter is a "D", return true; otherwise, return false;
         return left(obj,1)=='D';
     });
     // now let's add each filtered name to our master array of "D" names 
     arrayeach(matchednames,function(obj) {
          arrayappend(allDnames,obj);
     });
});</pre>
<blockquote><p><strong>See the <a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/filter/">live example</a> or grab the code from <a href="https://github.com/existdissolve/CF10/tree/master/filter">GitHub</a></strong></p></blockquote>
<h2>Wrapping Up</h2>
<p>As you can see, using CF10&#8242;s new <strong>ArrayFilter()</strong> function is pretty simple, and the <strong>ListFilter()</strong> and <strong>StructFilter()</strong> functions work exactly the same, just with slightly different parameters and return types.</p>
<p>But perhaps more importantly, this example shows how functions like <strong>StructEach()</strong> and <strong>ArrayFilter()</strong> can make processing of complex data structures a snap. Instead of bothering with messy for-loops in which it would be incredibly easy to lose our place, this approach feels much more sane and easy to follow.</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/02/coldfusion-10-filter-functions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ColdFusion 10: ArrayEach and StructEach, Hooray!</title>
		<link>http://existdissolve.com/2012/02/coldfusion-10-arrayeach-and-structeach-hooray/</link>
		<comments>http://existdissolve.com/2012/02/coldfusion-10-arrayeach-and-structeach-hooray/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 02:58:36 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[ArrayEach]]></category>
		<category><![CDATA[StructEach]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2373</guid>
		<description><![CDATA[Earlier today, I was looking through the &#8220;New Functions in ColdFusion 10&#8221; doc, and noticed a few gems: ArrayEach() and StructEach(). These are huge, because until now, there has been something of a disconnect between dealing with arrays and structures in CF, and their counterparts in other languages, like JavaScript. All JS libraries (like ExtJS)&#8230;]]></description>
			<content:encoded><![CDATA[<p>Earlier today, I was looking through the &#8220;<a href="http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WS890819DC-DE4D-4b24-A237-6E3483E9D6A1.html">New Functions in ColdFusion 10</a>&#8221; doc, and noticed a few gems: <strong>ArrayEach()</strong> and <strong>StructEach()</strong>. These are huge, because until now, there has been something of a disconnect between dealing with arrays and structures in CF, and their counterparts in other languages, like JavaScript. All JS libraries (<a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext-method-each">like ExtJS</a>) have &#8220;each&#8221; methods attached to basic objects which allows you to treat collections of the same kind of thing in a bulk way. Fortunately, CF10 introduces two very handy new methods to apply an &#8220;each&#8221;-like process to both arrays and structures.</p>
<blockquote><p><strong>NOTE</strong>: The ArrayEach() and StructEach() functions act on the original array/struct. Therefore, if you make changes to the array/struct within these functions (as in the ArrayEach() example below), the original array/struct will be affected (thanks Andy!).</p></blockquote>
<h2>ArrayEach()</h2>
<p>So, for example, let&#8217;s say you have an array of friends&#8217; names, and you want to make the list all uppercase. Pre-CF10, you might approach this by looping over the array, and executing a function at each iteration. Fine, easy enough, and it works. However, with <strong>ArrayEach()</strong>, you can ditch the clunkiness of the for-loop, and keep everything self-contained to the array. And, you can execute either an &#8220;inline&#8221; function, or call a named function. The two examples (which produce the same results) are below:</p>
<pre>names = ['John','mary','JOseph','Glenda','Mike'];

// named function
// notice that the function takes one argument, the value of the current iteration of the array
function makeLowercase(obj) {
    names[arrayfind(names,obj)] = lcase(obj);
}

<strong>//  run arrayeach() with an inline function</strong>
arrayeach(names,function(obj) {
    names[arrayfind(names,obj)] = lcase(obj);
});
writedump(names);

<strong>// run arrayeach() with a named function</strong>
arrayeach(myarray,makeLowercase);
writedump(myarray);</pre>
<blockquote><p><strong>See the <a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/each/array.cfm">live example</a> or grab the code from <a href="https://github.com/existdissolve/CF10/blob/master/each/array.cfm">GitHub</a></strong></p></blockquote>
<h2>StructEach()</h2>
<p>Not to be outdone, structures get some each() lovin&#8217; in CF10 as well. But instead of iterating over an array, the <strong>StructEach()</strong> function executes for every key-value pair in the structure. As with ArrayEach(), you can use either use an inline function or a named function.</p>
<p>In this example, we have a simple collection of &#8220;favorites,&#8221; which we want to print to the screen.</p>
<pre>favs = {color: 'blue', food: 'pizza', sport: 'basketball'};

// named function
// notice that the function takes two arguments, the key and value pair of the current iteration of the structure's key-value pairs
function getFavorites(key, value) {
    writeoutput('My favorite ' &amp; key &amp; ' is ' &amp; value);
} 
<strong>// run structeach() with a named function</strong>
structeach(favs,getFavorites);
<strong>// run structeach() with an inline function</strong>
structeach(favs, function(key,value) { 
    writeoutput('My favorite ' &amp; key &amp; ' is ' &amp; value);
});</pre>
<blockquote><p><strong>See the<a href="http://existdissolve-cf10beta.securecb1cf10.ezhostingserver.com/each/struct.cfm"> live example</a> or grab the code from <a href="https://github.com/existdissolve/CF10/blob/master/each/struct.cfm">GitHub</a></strong></p></blockquote>
<h2>Wrapping Up</h2>
<p>While these two functions probably won&#8217;t garner the attention that other additions will, I think they&#8217;re pretty dang awesome. Not only are they a long time coming (honestly, how often do you loop over an array&#8230;like 20 times every hour!!), but they help to make developing with these basic data types just a bit easier as they more closely align methodologies in CF with those you&#8217;d find elsewhere.</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/02/coldfusion-10-arrayeach-and-structeach-hooray/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ExtJS 4: Querying Records in a Data Store</title>
		<link>http://existdissolve.com/2012/02/extjs-4-querying-records-in-a-data-store/</link>
		<comments>http://existdissolve.com/2012/02/extjs-4-querying-records-in-a-data-store/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 04:29:55 +0000</pubDate>
		<dc:creator>existdissolve</dc:creator>
				<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[Store]]></category>

		<guid isPermaLink="false">http://existdissolve.com/?p=2371</guid>
		<description><![CDATA[As you come to use data stores regularly within ExtJS applications, you&#8217;ll quickly come to realize just how powerful they are. With very little code, you can create robust data repositories that can not only store complex data, but can (perhaps more importantly) drive components within your applications. At some point, however, you&#8217;ll need to&#8230;]]></description>
			<content:encoded><![CDATA[<p>As you come to use <a href="http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store">data stores</a> regularly within ExtJS applications, you&#8217;ll quickly come to realize just how powerful they are. With very little code, you can create robust data repositories that can not only store complex data, but can (perhaps more importantly) drive components within your applications.</p>
<p>At some point, however, you&#8217;ll need to retrieve data from your Store in a query-like manner. That is, instead of looking up a record by a known ID or position within the store, you may need to find one or more records based on a search term, a category, or whatever else is required by your app.</p>
<p>Of course, as with everything else, ExtJS makes this pretty simple. Let&#8217;s suppose that we have the following Model:</p>
<pre>Ext.define("MyApp.model.Bookmark", {
     extend: "Ext.data.Model",
     idProperty: "id",
     fields: [
         {name: "id", type: "int"},
         {name: "target", type: "string"},
         {name: "title", type: "string"},
         {name: "category", type: "string"},
         {name: "created", type: "date"}
     ]
});</pre>
<p>Nothing to crazy here. Just a simple model with some standard kinds of fields for storing data, in this case, &#8220;bookmarks.&#8221; Now, let&#8217;s define our data store:</p>
<pre>Ext.define("MyApp.store.Bookmarks", {
    extend: "Ext.data.Store",
    model: "MyApp.model.Bookmark",
    autoLoad: true,
    storeId: 'bookmarks',
    proxy: {
        type: 'localstorage',
        id  : 'myapp-bookmarks'
    }
});</pre>
<p>As with the model, this is very straightforward. We&#8217;ve configured a simple store which happens to have a localStorage proxy (change it if you want&#8211;ExtJS doesn&#8217;t care!).</p>
<h2>Simple Data Lookup</h2>
<p>Ok, so now that we&#8217;re up and running with our model and store, let&#8217;s pretend we&#8217;ve created a simple app to save bookmarks into our data store. As we&#8217;re plugging along, we find that we need to put some kind of tollgate in place to prevent the same bookmark from being entered over and over: after all, having one bookmark to <a href="http://www.youtube.com/watch?v=QFCSXr6qnv4&amp;feature=related">Charlie the Unicorn 2</a> is certainly enough!</p>
<p>How can we prevent this? In our <strong>addBookmark()</strong> method, we can do a simple lookup on our data store to see if a bookmark with the same title already exists. This might look something like so:</p>
<pre>function addBookmark(target,title,category) {
    var store = Ext.data.StoreManager.lookup('bookmarks');
    var match = <strong>store.find('title','title');</strong>
    if(match == -1) {
        ...add the bookmark
    }
}</pre>
<p>In this simple example, we use the store&#8217;s <strong>find()</strong> method to search through the store&#8217;s records. The <strong>find()</strong> method takes two required arguments&#8211;the column to search, and the value to be used in the search&#8211;but has more flexibility for case-sensitivity, partial matches, etc. Based on whether the index of a record in our store is returned, we decide whether or not to add the new data to our store.</p>
<blockquote><p>Of course, if we don&#8217;t care about the index of the record and simply want to get a matched record, we could use <strong>findRecord()</strong> instead. It functions in the same way, but returns a model instance instead of a record index.</p></blockquote>
<h2>More Complex Data Lookup</h2>
<p>The store&#8217;s <strong>find()</strong> and <strong>findRecord()</strong> methods are great if you only need to find matches based on a single data column. What if you need to match on more than one column, though? For example, let&#8217;s say that we want to be able to store bookmarks with the same title as long as they belong to a different category. Obviously, our previous method will not work, since the method will prevent insertions of records with already-existent titles. Nope, we need something a bit more robust. Thankfully, ExtJS data stores have just the ticket: <strong>findBy()</strong>.</p>
<p>The <strong>findBy()</strong> method&#8217;s power lies in the fact that you can specify a custom function that will be executed against every record in the data store. Within this custom function, you can do any manner of checks on the entire data record (not just the value of one column). If the conditions you specify succeed, the method will return the index of the first matching record.</p>
<p>So here&#8217;s what that might look like for our scenario of checking for the uniqueness of both bookmark title AND category:</p>
<pre>function addBookmark(target,title,category) {
    var store = Ext.data.StoreManager.lookup('bookmarks');
    // custom function for finding record with complex criteria
    var match = <strong>store.findBy</strong>(function(record,id) {
        if(record.get('target')==target &amp;&amp; record.get('category')==category) {
            return true;
        }
    });
    if(match == -1) {
        ...add the bookmark
    }
}</pre>
<p>As you can see, the custom function is passed two arguments: the model instance of the currently-evaluated record, and the id of the record. Since we want to check to make sure that the combination of bookmark title and bookmark category are unique, we can simply check the &#8220;title&#8221; and &#8220;category&#8221; values of the would-be-bookmark against each model in our data store. If no match is found, we know the record is unique and we can add it to the data store. Magical <img src='http://existdissolve.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Wrapping Up</h2>
<p>Obviously, the example provided above is very simple; however, I hope it shows just how easy it is to not only query data from a data store, but moreover to create custom functions to apply more complex query logic to the data in your stores.</p>
]]></content:encoded>
			<wfw:commentRss>http://existdissolve.com/2012/02/extjs-4-querying-records-in-a-data-store/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

