Photo from Chile

CF9 ORM Quick Tip - Removing All Items from A Collection

For this example of using ColdFusion 9's ORM features, let's assume we have a User object and a Department object. The Department has a collection of Users, like so:

view plain print about
1component persistent="true" output="false" entityname="Department" {
2    property name="DeptId" fieldtype="id" generator="native";
3    property name="Name";
4    property name="Users" fieldtype="one-to-many" type="array"
5        cfc="User" fkcolumn="DeptId" singularname="User";
6}

Let's also say that Department 1 currently has 3 Users assigned to it, call them User1, User2 and User3. Now, we want to write some code that will empty the Department's collection of Users. A first attempt might look something like:

view plain print about
1Users = Department.getUsers();
2for (i = 1; i LTE ArrayLen(Users); i = i + 1) {
3    Department.removeUser(Users[i]);
4}

But this won't work. In fact, if you run that code you'll see that you end up with a Department that still has User2 assigned to it. The reason this happens is that as soon as you remove User1 from the collection, the array shrinks, so User2 now occupies position 1 and User3 occupies position 2. So the next time through the loop, User3 gets removed (because i now equals 2) and Users[2] is User3. Then the loop finishes because the condition is met.

[More]

An Object Oriented Approach to Validations - Recording Available

I'm happy to announce that the presentation that I delivered to the Online ColdFusion Meetup last night, entitled An Object Oriented Approach to Validations, was recorded and is therefore available to anyone who is interested and wasn't able to attend in person.

Towards the end of the presentation I listed some resources that exist for ValidateThis!, which is the framework that I created using the approach that I described. Those are:

  • Riaforge Site (framework and demo code) - validatethis.riaforge.org
  • Online Demo - www.validatethis.org
  • Google Group - groups.google.com/group/validatethis

This presentation was very much about why I created VT and how I designed it. It didn't really address questions of how one uses the framework or how to integrate it into an existing application. I have blogged about that extensively in the past, but I also plan on putting together a new presentation addressing those issues, which I hope to present to the meetup group in the future.

I'd like to thank everyone for attending and for all of the wonderful feedback, and I'd also like to thank Charlie Arehart for allowing me to speak and for continuing to operate this amazing resource.

Presenting An Object Oriented Approach to Validations to the Online ColdFusion Meetup

Just a quick note to announce that I'm going to be presenting my session from cf.Objective() to the Online ColdFusion Meetup this Thursday, June 18th, at 6:00pm EDT.

Details can be found at the Meetup site. You can attend the presentation via Connect on Thursday. The session will be recorded and made available.

Here is the abstract for the presentation:

Performing validations on user input is something that all of us, as application developers, must do. When moving from a procedural to an object oriented approach many developers have difficulty determining how and where to perform validations. In this session you will be introduced to an object oriented approach to validations. This approach enables you to add validation "smarts" into your business objects, while keeping that logic fully encapsulated outside of the objects, meaning that any changes to your validation rules and/or logic will have zero impact on the rest of your model. We'll look at the individual objects that comprise this approach, and understand how they work together to automatically perform server-side and generate client-side validations using metadata from a simple xml file. You will leave the session with a better understanding of how to design using objects, as well as a tool that will greatly simplify the task of adding validations to your object oriented application.

This session is aimed at intermediate to advanced developers who are familiar with object oriented concepts and are interested in learning about how to incorporate validations into their objects, as well as object oriented design in general.

Hope to see some of you there.

ValidateThis! 0.75 - Now Supports Internationalization (i18n)

A developer named Mischa Sameli asked a question about supporting internationalization (i18n) in ValidateThis!, my validation framework for ColdFusion objects, on the ValidateThis Google Group a few weeks ago. His questions got me thinking about how I might do that, and those thoughts turned into design ideas, which turned into code. So I'm happy to announce that the latest version of VT, just released to RIAForge, has full support for i18n. I have created a new i18n demo which shows off this new feature in all of its glory. If you visit that demo page you'll see that you can switch languages between English and French.

So, what does i18n support in VT mean? In a nutshell, it means that all validation failure messages, both on the client side and on the server side, can now appear in multiple languages within a single application. A developer still only has to specify the metadata for each validation rule once (which is the primary objective of the framework), with the translations being performed by a translation layer.

[More]

Building An Object Oriented Model - Recording and Sample Code Available

I'm happy to announce that the presentation that I delivered to the Online ColdFusion Meetup last Thursday night, entitled Building an Object Oriented Model, was recorded and is therefore available to anyone who is interested and wasn't able to attend in person. Don't be put off by the fact that the recording is 90 minutes long - the presentation is only 60 minutes, and is followed by a 30 minute Q and A session.

A few people asked about the sample code that I presented. It can be downloaded directly from this post.

Also note that I have written a number of posts on these topics, so anyone looking for more information can check out the OO Design category of this blog.

I'd like to thank everyone for attending and for all of the wonderful feedback, and I'd also like to thank Charlie Arehart for allowing me to speak and for continuing to operate this amazing resource.

Finally, I will be presenting my other cf.Objective() presentation, An Object Oriented Approach to Validations at an Online ColdFusion Meetup session in the near future, date and time TBA.

Presenting Building An Object Oriented Model to the Online ColdFusion Meetup

Update: A recording of this presentation, as delivered to the Online ColdFusion Meetup is available via this blog post</>.

Just a quick note to announce that I'm going to be presenting my session from cf.Objective() to the Online ColdFusion Meetup this Thursday, May 28th, at 6:00pm EDT.

Details can be found at the Meetup site. You can attend the presentation via Connect on Thursday. The session will be recorded and made available.

Here is the abstract for the presentation:

When making the move from a procedural to an object oriented approach one often comes across a pattern that involves using services and gateways to act as a middle man between a controller and your actual business objects. This session will present an approach to implementing a common set of services and gateways. Through the use of abstract classes you will see how to eliminate duplicate code and how to encapsulate logic to increase the cohesiveness of your entire model. We will start with the basics, describing what services and gateways are, and then look at building a model from the ground up. You'll leave the session with an understanding of the components that go into building a model, as well as some of the object oriented principles that will help guide you in your design efforts.

This session is aimed at beginning to intermediate developers who have some experience with and knowledge of basic OO concepts and are interested in learning about some of the design considerations that go into building an OO model.

Hope to see some of you there.

Building An Object Oriented Model - Presentation Materials Available

Update: A recording of this presentation, as delivered to the Online ColdFusion Meetup is available via this blog post</>.

The slides and sample code from my cf.Objective() presentation, Building An Object Oriented Model, are now available. Click on the links below to download them. I have also uploaded my presentation to SlideSix.

Here is the abstract for the presentation:

When making the move from a procedural to an object oriented approach one often comes across a pattern that involves using services and gateways to act as a middle man between a controller and your actual business objects. This session will present an approach to implementing a common set of services and gateways. Through the use of abstract classes you will see how to eliminate duplicate code and how to encapsulate logic to increase the cohesiveness of your entire model. We will start with the basics, describing what services and gateways are, and then look at building a model from the ground up. You'll leave the session with an understanding of the components that go into building a model, as well as some of the object oriented principles that will help guide you in your design efforts.

This session is aimed at beginning to intermediate developers who have some experience with and knowledge of basic OO concepts and are interested in learning about some of the design considerations that go into building an OO model.

Regarding the slide deck, it does not convey much meaning without my commentary, but the pictures are pretty ;-)

Regarding the sample code, it is designed to illustrate various points made throughout the presentation. It is not identical to the code that I would use in an actual application. Feel free to look at it for ideas, but I don't encourage people to use it as an example of best practices for writing services and gateways. I have written a number of blog posts on that topic, which can be found in the OO Design category of my blog.

If anyone is interested in having me deliver this presentation to a ColdFusion User Group via connect please feel free to leave me a comment, or send me an email.

Attachments:

More Entries