So you want to create a ModelGlue:Unity application? ( Part 6 )

In the next few series, our Contact-O-Matic will persist data in a database. The queries and relationships are simple and should translate over to any database. Our code will be organized into two types of components the DAO (Data Access Object) and the Gateway. These two components are common structures used in many Object Oriented systems and a quick google search will land you on endless descriptions for each. For our purposes, all we need to know is the DAO and Gateway will help us organize our code into sections. The DAO is for pulling back a single object, the Gateway for a query of objects.

Another architectural feature of our Contact-O-Matic is our ContactService.cfc component. Service components help tie your other components together. Note how simple it will be to add in new database functionality.

At the end of series 5 of our Contact-O-Matic, we had a ContactService component which returned the ContactType data , a single contact object and a list of contact objects. Even though we are going to add a DAO component as well as a Gateway component, they will be tied together within the service component.

Some of you might be asking yourselves why we have all of these components. After all, there are huge and complex ColdFusion applications written without a single component. Couldn't we just put our queries in the Controller and be done with it? That is a very valid question to ask. You should be proud of thinking of it. Question Everything!!!

The main point of these separations in our code is to isolate variability. Meaning, when the application needs a feature, or a new data column, the affected sections in our code are compartmentalized and perhaps only one section of code needs to change in order for the entire application to be upgraded with the newest feature.

The complete source code up to the end of series 5 is attached to this article. It will be easier to follow along if you use this code.

A few quick notes before we begin:

  1. Remember that the application files will be cached if the ModelGlue reload setting is 'false'. Any changes to Controllers, components created with ColdSpring, or stored in the Controllers will NOT change until you reload the application. This trips me up sometimes and my first step is to ALWAYS reload the framework
  2. The <include /> tag is processed by BlogCFC as a cfinclude. Thus, whenever I paste in an event-handler section with an <include tag, I always have to use the entity symbol '& lt;' or i'll get an error when I post it. I try to leave a small note at the end of the code block about changing this in your code. If I forget, just know an XML tag will never actually start with '& lt;'
  3. I am writing this tutorial with MSSQL server (delete derogatory note about Microsoft Products). Your database might have a slightly different syntax and I trust you to convert it over

Lastly, our database will have two tables:

Contact
ColumnName ColumnType Other
ContactID int Primary Key
ContactName varchar( 255 ) not null
ContactType int null
ContactType
ColumnName ColumnType Other
ContactTypeID int Primary Key
ContactType varchar(100) not null

Without further ado, let us get to the next piece in our Series, database support.

Download Download

Sometimes it is the obvious......

I spent several hours going over a new ModelGlue:Unity + Transfer set up and had an error that stumped me. For the life of me I couldn't get any scaffolds to work. ModelGlue and Transfer loaded up perfectly, Directly querying the database worked perfectly. All signs pointed to GO, except for the lack of any scaffolded events working.

Oops!

Message Model-Glue: There is no known event handler for "skiresort.list".

Now, I've set this up several times so I was sure I misconfigured something. I checked every possible thing I could think of that could be holding this up and then started cfdumping the internals of the frameworks. Getting nowhere fast, I started complaining about it in the IRC channel and the second I started explaining it, the answer came to me. So for public humiliation and for posterity, here is the answer.

If you want to access the event-handlers generated by the scaffolding feature, the <scaffold /> tag in the modelglue.xml file MUST be contained in the <event-handlers /> tag.

This is Bad

view plain print about
1<scaffold object="skiresort" type="list,view,edit,commit,delete">
2    <results>
3        <result do="view.template" />
4    </results>        
5</scaffold>
6
7<event-handlers>

This is Good

view plain print about
1<event-handlers>
2
3<scaffold object="skiresort" type="list,view,edit,commit,delete">
4    <results>
5        <result do="view.template" />
6    </results>        
7</scaffold>

I shall hang my head in shame for the next 5 minutes....

MG:U series, interlude

I am planning out the next few steps in our ModelGlue:Unity series and would like to tally a vote. Currently our Contact-O-Matic is barebones. We went over how to use portions of ColdSpring to manage our service and to pass in configuration parameters. We also went over adding ModelGlue results to change the programmatic flow of the application. Following this pattern, you should have a good base on ModelGlue:Unity.

However, apart from the tabs, it has a plain-jane look and feel. Heck, it doesn't even save the contacts for very long ;). Before all is said and done, we will add in database persistance, security, the Transfer ORM and some Ajax.

We are going to need to put database persistance really soon as it is keeping us from our larger goals. After that, there are three different paths we can go.

In the spirit of Choose Your Own Adventure ( man, I loved those books ) which would you rather we tackle next? The choices once again:

  1. Easy MG:U Security
  2. MG:U scaffolding with Transfer ORM
  3. Ajax Enhancements

Also, if you are following along with the series, please leave a comment or send me an email with the database you use on your development server. I am going to make an effort to be as cross-DB as I can....

So you want to create a ModelGlue:Unity application? ( Part 5 )

Previously in this series, we installed the ModelGlue:Unity framework and the ColdSpring framework. We used the ModelGlueApplicationTemplate as the skeleton, added our basic flow and navigation. We can save and list contacts and our validation is working nicely,

In this section of our Contact-O-Matic, we will pull out the contact types values from coldspring and used them to add defined categories to our contacts. In a previous segment, we added the Contact Types as a 'map' in ColdSpring, now we will pull out the values and add them to our form.

[More]

ColdFusion list functions in Javascript?

How many times have you wished for that?

ColdFusion is tops at list parsing. I remember back in the day all my data structures were either lists or structs. With some combination of structs and lists, I could solve anything. Of course, that was before UDFs and Components and all that.

Anyways, Topper at cftopper has made available javascript functions that operate on lists. The wait is officially over. No more tossing about with ugly looking arrays.... ;)

Have a look

UPDATE: There are at least two three other CF/Javascript projects out there:

1. From Leftcorner JavaScript Library of ColdFusion Functions.

This is a JavaScript library that emulates many ColdFusion functions. It is useful for ColdFusion developers who are new to JavaScript or who want to maintain consistency in a ColdFusion and JavaScript mixed application. It is also useful for developers who prefer the ColdFusion (and Visual Basic) syntax of invoking functions.

2. From Shlomy Gantz CFMLjsLibrary

Basically it is a translation of ColdFusion functions to javascript.

3. For the JQuery fans from Christopher Jordan CFJS for jQuery is a set of ColdFusion functions written for JavaScript and can be accessed as $.funcName();

Customizing Flex Components at NYFLEX

On January 18th, Michael Labriola presented 'Customizing Flex Components' to the New York Flex user group. There was a bit of bad weather which kept roughly half of the 40 prospective attendees from making the meeting. Those of us who went were in for an excellent presentation from a man who really knows his Flex.

In Flex, components are essentially wrapped functionality, quite similar to custom tags in CFML. You can extend a particular component with ActionScript 3 to have custom appearance or behaviors or whatever else you can dream up. When complete, the result is a new tag to use in your flex code.

In addition to what was the most comprehensive overview of the Flex framework and the internal states, we were also shown the underlying ActionScript code of the Flex Framework. This is quite useful when extending components as it is easy to find out what behaviors and parameters are available to subclasses. Now, when I wonder why a particular component behaves in a certain way, or if I can pass it an ArrayCollection in place of an Array, I know where to find my answers. This has already saved me hours of scanning the web, the flexcoders list and the help files.

I am a big fan of the "Teach a man to Fish..." theory and appreciate knowing how to get myself out of those sticky Flex knots I seem to get myself into.

Shlomy Gantz the leader of the NYFLEX user group, consistantly puts together practical sessions from excellent members of the Flex community. If you happen to be in NYC when the NYFLEX group meets, definately stop in.

Michael Labriola, one of the authors of Adobe Flex 2: Training from the Source, is an engaging and entertaining speaker. He is also very generous with his time. Baz Karam and I bent his ear for a while after the meeting, peppering him with question after question. Michael answered all of our questions clearly, insightfully and patiently. I can't say enough good things about him.

Michael is a principal with www.digitalprimates.net so if your organization is in need of a top Flex consultant to train your team, I give him the highest recommendation.

3436 Views Print Print Comments (0) Flex

So you want to create a ModelGlue:Unity application? ( Part 4 )

Previously in this series, we installed the ModelGlue:Unity framework and the ColdSpring framework. We used the ModelGlueApplicationTemplate as the skeleton, added our basic flow and navigation. Finally we can save and list contacts Our Contact-O-Matic is moving right along.

In the last segment, we tested the 'failure' path and were routed back to the form. We also tested the 'success' path and were routed to the contact list. Open the ContactFormBean.cfc located in *ContactManagerMG/Model and edit the validate function (You did check the validate box in the rooibos generator like the last series said, didn't you ;) )

Our validate function should have the returntype of boolean. We will pass in a structure to hold any error messages and check the lengths of our two properties ContactName and ContactType. Your validate function should look like this:

[More]

So you want to create a ModelGlue:Unity application? ( Part 3 )

Previously in this series, we installed the ModelGlue:Unity framework and the ColdSpring framework. We used the ModelGlueApplicationTemplate as the skeleton then we added our basic flow and navigation. Our Contact-O-Matic is moving right along.

In this segment of our regularly scheduled programming, we look a bit deeper into ColdSpring, add the contact form and contact list.

[More]

Download Download

So you want to build a ModelGlue:Unity application (Part 2)

Previously in this series, we installed the ModelGlue:Unity framework and the ColdSpring framework. We used the ModelGlueApplicationTemplate as the skeleton for our new Contact-O-Matic 1.0 alpha (don't worry, we'll eventually make this a Web 2.0 application). We rejoiced when we ran our application and now will look at some essential information about our new set-up.

Let's begin with opening the Application.cfm file and giving our application a name. Set the name attribute of the application tag to 'ContactManagerMG'. If for some reason, you already have another application on your server with the name of ContactManagerMG, put another name here.

Next, as ModelGlue uses ColdSpring for configuration, let us look at some key sections of the framework config. Open the *ContactManagerMG/config/ColdSpring.xml file in your editor. There are two beans defined by default, one with the id of 'modelGlueConfiguration' and one with the id of 'reactorConfiguration'. The 'reactorConfiguration' bean is for yet another framework you could use with ModelGlue. We won't need the 'reactorConfiguration' for this series and you may delete that bean from your ColdSpring.xml file.

Ok, now look closer at the 'modelGlueConfiguration'. The property tags define how your application will behave.

[More]

So you want to create a ModelGlue:Unity application? ( Part 1 )

In this series, we will create a ModelGlue:Unity application. Our example application will manage contacts. We will start with a blank canvas and by the end of the series, have a functional application.

Lets begin:

Firstly, you should have the ModelGlue:Unity and Coldspring framework installed. If the framework is not installed, have a look at this post.

Our application will reside in a directory just under the webroot. We will access our application at http://LocalHost/ContactManagerMG. With that in mind, lets open the ModelGlueApplicationTemplate Directory.

This directory serves as an application skeleton for which to begin a new ModelGlue:Unity application.

There are two ways to get a new application up quickly. The first way is to copy the contents of the ModelGlueApplicationTemplate into a new directory just under your webroot called ContactManagerMG. Do a find and replace on 'modelglueapplicationtemplate' and change it to 'ContactManagerMG'.

The second way assumes you have cfeclipse or some other ANT environment. The directions below are specifically for cfeclipse.

Inside the ModelGlueApplicationTemplate directory is a file called build.xml. Build.xml is an ANT script. ANT scripts are sets of commands used to perform file and directory tasks. There are certain parts of the ModelGlueApplicationTemplate that need to be changed to our application name ( ContactManagerMG ).

We will now make the modifications to the build.xml file for the purpose of creating our new application.

Open the build.xml file. On a default install of ModelGlue:Unity the file will look like so:

view plain print about
1<project name="New Model-Glue Application" default="build">
2    <property name="source" value="c:\inetpub\wwwroot\modelglue\modelglueapplicationtemplate"/>
3    <property name="target" value="c:\inetpub\wwwroot\"/>
4
5    <target name="build">
6        <copy todir="${target}">
7            <fileset dir="${source}" />
8        </copy>
9    
10         <replace
11     dir="${target}"
12     token="modelglueapplicationtemplate"
13     value=""
14     />

15    </target>
16</project>

In plain English, the build.xml file will copy the contents from the 'source' directory and place them into the 'target' directory then replace each instance of the 'token' and replace it with 'value'.

Make the following changes to the file and then run it.

IIS

view plain print about
1<project name="New Model-Glue Application" default="build">
2    <property name="source" value="C:\inetpub\wwwroot\modelglueapplicationtemplate"/>
3    <property name="target" value="C:\inetpub\wwwroot\ContactManagerMG"/>
4
5    <target name="build">
6        <copy todir="${target}">
7            <fileset dir="${source}" />
8        </copy>
9    
10         <replace
11     dir="${target}"
12     token="modelglueapplicationtemplate"
13     value="ContactManagerMG"
14     />

15    </target>
16</project>

Apache

view plain print about
1<project name="New Model-Glue Application" default="build">
2    <property name="source" value="C:\httpd\Apache2\htdocs\modelglueapplicationtemplate"/>
3    <property name="target" value="C:\httpd\Apache2\htdocs\ContactManagerMG"/>
4
5    <target name="build">
6        <copy todir="${target}">
7            <fileset dir="${source}" />
8        </copy>
9    
10         <replace
11     dir="${target}"
12     token="modelglueapplicationtemplate"
13     value="ContactManagerMG"
14     />

15    </target>
16</project>

Once your edits are complete, save the file and locate it in the navigator. Right click on the file and choose Run As -> ANT Build. You can see the progress in the console. Assuming no errors, you now have a new ModelGlue application and can begin coding.

Via Find and ReplaceANT build, you now have a new directory called ContactManagerMG. Run this in your browser and you should get a page showing the following:

Model-Glue 2.0: Unity

Model-Glue is up and running!

Voila. A new ModelGlue:Unity application. In the next series, we will add some functionality to our application.