Iterator on RIAForge, and Updates to FormUtils and ColdSpring Utils

The blog has been quiet lately, but that should be changing now that I'm finally doing some real work with ColdFusion 9! In the meantime, I've committed a few minor updates to some RIAForge projects, and added a new one.

The new project is Collection Iterator. This is simply a CFC that allows you to iterate the same way over queries, lists, structures, or arrays. The syntax is simple:

var array = ['foo', 'boo', 'zoo'];
var iterator = new Iterator( array );
var counter = 0;

while( iterator.hasNext() )
{
    counter++;
    var thisRow = iterator.next();
    assertTrue( array[counter] == thisRow, "Array element not found." );    
}

assertTrue( counter == 3, "Iterator did not loop the correct number of times." );
		

The obvious benefit is that it lets you handle all four collection types in a standard way. This is a CF9-only component, as it is written using the new script-only CFC syntax (which I LOVE, but will be talking about further in future entries).

As for updates, I fixed a bug in the DynamicXMLBeanFactory, which is part of the ColdSpring Bean Utilities library. There was an issue when using ColdSpring configuration files that imported multiple other config files. The CFC was also modified to only attempt to do an ExpandPath() on the configuration file location if a file doesn't exist using the value supplied by the developer. I also updated the FormUtils CFC to make the constructor arguments optional, to make it easier to configure and use.

So, that's all for now, but look for some entries on CF9 ORM tips and techniques, as well as a full reboot of my earlier series on the Swiz framework for Flex. Swiz 1.0 alpha was just released, and as the finishing touches are added I plan to be blogging about all the excellent new capabilities that have been added by the Swiz team!

Comments Comments (5) | del.ico.us del.icio.us | Digg It! Digg It! | Linking Blogs Linking Blogs | 5692 Views

My IECFUG Presentation Recording and Files

Last Friday I gave a presentation to the Inland Empire ColdFusion User Group. It covered a range of topics: MXUnit, ColdMock, and elements of my RIAForge FormUtilities and ColdSpring Bean Utilities projects.

The presentation went well, I think. There are a few technical issues towards the end when they were trying to set up a microphone to get a Q&A going, but they are minor. I've linked to the files and the recording below in case anyone is interested in having a look. Thanks again to Sami, Luis, and the IECFUG for allowing me to present!

del.ico.us del.icio.us | Digg It! Digg It! | Linking Blogs Linking Blogs | 7241 Views

FormUtilities CFC Now At RIAForge

Just a quick note that I've created a project at RIAForge for this CFC at http://formutils.riaforge.org/. This will make it easier to keep track of any problems or bugs if they arise. Thanks again for all the interest!

Comments Comments (1) | del.ico.us del.icio.us | Digg It! Digg It! | Linking Blogs Linking Blogs | 6127 Views

FormUtilities CFC Code Released (Create Implicit Arrays and Structures from Form Fields)

OK, folks were clamoring for the code so I've released it. You can download it from the Links sidebar pod. Please let me know if you find any problems with it. Assuming testing goes well, I'll release it as a project on RIAForge.

del.ico.us del.icio.us | Digg It! Digg It! | Linking Blogs Linking Blogs | 6685 Views

Implicit Creation of Arrays and Structures from Form Fields

I remember back in 1999 when I first started using Fusebox. The idea of taking all form and URL variables and keeping them in the attributes scope was brilliant. Now, all of the frameworks do something similar to wrap up the incoming variables, usually into an event object with event arguments.

However, one thing has always bugged me, and that is the "all or nothing" way that this is done. Many are the times I've had to pass the entire event arguments structure into a CFC just to get at a subset of them, perhaps the ones in the edit form for a User. I may want to use just the form fields for the User to populate a Bean or a Transfer Object. But getting at just those values can be difficult or somewhat kludgy, like passing in the whole struct as an argument collection and then relying on cfargument tags on the other side to actually whittle it down.

To help with this, I've created a CFC that will let you implicitly create arbitrary arrays and structures based on the names of your form fields. For example, this form:

<input name="user.id" type="text" value="user"><br />
<input name="user.name" type="text" value="user"><br />
<input name="user.password" type="text" value="user"><br />
		

Would be parsed and turned into this on the server:

Here are more examples to demonstrate the ability to do this as far as you need to go. Create arrays or structures within a structure, as well as a list of values if the fields have the same name (such as checkboxes):

<input name="user2.id" type="text" value="user2"><br />
<input name="user2.name" type="text" value="user2"><br />
<input name="user2.password" type="text" value="user2"><br />
<input name="user2.permission[2]" type="text" value="user2.permission[2]"><br />
<input name="user2.permission[1]" type="text" value="user2.permission[1]"><br />
<input name="user2.category.11" type="text" value="user2"><br />
<input name="user2.category.8" type="text" value="user2"><br />
<input name="user2.userType" type="text" value="user2type1"><br />
<input name="user2.userType" type="text" value="user2type2"><br />
		

Create an array of structures, that each contain their own arrays and structures. This can be handy for dynamic forms where you don't know how many sets of data will be on the page:

<input name="employee[1].name" type="text" value="employee[1]"><br />
<input name="employee[1].phone" type="text" value="employee[1]"><br />
<input name="employee[1].permission.2" type="text" value="employee[1].permission.2"><br />
<input name="employee[1].permission.1" type="text" value="employee[1].permission.1"><br />
<input name="employee[1].mode[2]" type="text" value="employee[1].mode[2]"><br />
<input name="employee[1].mode[1]" type="text" value="employee[1].mode[1]"><br />

<input name="employee[2].name" type="text" value="employee[2]"><br />
<input name="employee[2].phone" type="text" value="employee[2]"><br />
<input name="employee[2].permission.2" type="text" value="employee[2].permission.2"><br />
<input name="employee[2].permission.1" type="text" value="employee[2].permission.1"><br />
<input name="employee[2].mode[1]" type="text" value="employee[2]mode[1]"><br />
<input name="employee[2].mode[2]" type="text" value="employee[2]mode[2]"><br />
		

And lastly, a demonstration that the structure can be arbitrary if you had some need for it to be:

<input name="company[1].name.firstName.prefix" type="text" value="company[1]"><br />
<input name="company[1].phone[2].something[5]" type="text" value="company[1]"><br />
		

I'm considering cleaning this up and putting it up on RIAForge as a Form Utility CFC. Personally, I think it would be great just to pass in the User structure and know that all it has is the user-related form fields and nothing more. What do folks think? Would you use this as an alternative to passing in a whole event structure?

Comments Comments (24) | del.ico.us del.icio.us | Digg It! Digg It! | Linking Blogs Linking Blogs | 15508 Views