Thursday, October 25, 2007

Flex2 connection debugging

Ok, so it took me way too long to find out about this. Flex2 lets you track what' s happening with your remote connections using a tool similar to the Flash Connection Debugger. All you have to do is add <TraceTarget/> after your application tag. After that, when you launch the debug version of your app, you'll see all the traffic going back and forth between flash and your remote amf technology (in my case, ColdFusion). It's a huge help when your app just seems to hang when attempting to connect to a remote service. Too bad it spits its output into the console window instead of the neat little app that ships with Flash. A collapsed panel in the debug view would do just as well. Let me know if there is one and I just haven't found it.

One thing I've noticed that I haven't found a solution for is that the information provided by the TraceTarget tag/object doesn't include information received from your remote service provider. That's going to be a problem with CF since it has a habit of doing things like changing the case of your objects properties or your code is returning a generic object when you had intended for it to be typed.

You can still see the results of the information coming back in the variables panel in eclipse using the debugging perspective, but I got used to the Flash NetConnection debugger where everything was in one place. No big deal, I'm sure we all can get used to a slightly different workflow.

Friday, October 19, 2007

flex2:TFS on my mac

I'm going to use this entry mainly as a place to mark down some of the issues I encountered going through the last third of the flex2:Training from the Source book. First, I guess it's important to describe the environment I'm working in because it's not exactly what the book was looking for.

My Environment
  • Mac book pro on OS X
  • flex 3 beta 2 (not the same as the book, but issues have been minimal. The only thing I remember being different has been a few screen shots at the beginning of the book. No big deal.
  • MySQL 5.0 beta (very stable at this point, although the gui tools occasionally abend on the mac)
  • ColdFusion 8 developer edition installed to use the embedded Apache web server on OS X
In order to finish the book, you need to set up a ColdFusion site on your local computer. The site is included on the CD that is distributed with the book, but it's inside the ColdFusion for windows zip file. I've extracted the flexGrocer CF site and updated a few of the xml files that were only found on and put a copy up on my share account. You won't have to bother with unpacking the entire ColdFusion install to get the site. Both of the folders should be unpacked to your web root. You might also want to create a cf project (using cfeclipse, of course) to point to the sites in case you need to make an edit or two.

  • page 397 - This is the first place I had to deviate from the text a bit. My local webserver uses the default port, so I was able to remove the :8300 from the httpservice entries. Also, a few of the xml files were not in my copy of the site from the cd. I was able to fetch them from the site and I've included them with the site download mentioned above.
  • oops. A bug in the script I posted with the db. I named a field in the unit table "uintID". I've corrected the typos (it wound up in several places) and posted the corrected file back on my share.
  • MySql uses tinyint(1) as a boolean and mssql server records boolean values as 1 or 0 (or null, but we won't take that on here). You'll need to modify the addProduct method of the productManager.cfc file on the cf website to handle booleans coming into the object with 'yes' and 'no' values. I just did a little inline iff like this: iif(arguments.aProduct.isOrganic,1,0), and the same for isLowFat.
  • Do the same thing for the updateProduct method in the productManager.cfc file as well.
  • Edit the cffile file attribute of the productManager.cfc in the ColdFusion part of flexGrocer to point to your local install of cf.
  • Edit flexGrocer(CF)/cfcs/fileUpload.cfm to point to your flexGrocer/assets directory.
  • Edit the FlexGrocer_CF_Services.xml file that is used in your flex2 compiler settings to point to your install of ColdFusion's flash services. For me, this is: http://localhost/flex2gateway/
  • Page 428: I'm not sure if this is something strange with my setup, an error I have in the code, a difference between running on a Mac vs WinTel or an issue with the book. In order for the remoting lesson to actually work for me, I had to change the Alert command in step 12 to refer to the event result as event.result.ORDERNUM. I know there have been issues with case involving coldfusion remoting in the past, and I guess this is just another instance of that. Note that the text explains that we are expecting a generic Object and not an OrderInfo instance. I think if we had an alias for the coldFusion component in our OrderInfo vo, we might be able to return a typed object and preserve the property case with the use of the cfproperty tags. If I get some time later, I'll have to look into this.

Thursday, October 18, 2007

Flex2:TFS with MySQL for OSX

Here I am, having a lot of fun working through the "Adobe Flex 2:Training from the Source" book. Some of it is a bit of a rehash for me since I've been dabbling with flex for some time, but I like the way the book takes you through pretty much one application all the way through. It helps build continuity as you work and you get to see the thing take shape. Much better than the little code snippets you get in a lot of books when you're trying to learn a new technology. Those work better when the book turns into a reference.

So here I am, about two thirds of the way through the book, getting ready for the really good bits, when the book goes all Microsfty on me. I have to install cf on windows and hook it up to an access database. Well, I'll have none of that. So I took a few hours today to build a script that would do the same job in MySQL. You can get it from my share, as well as a script to drop everything and start over. The only thing you have to know from here is that I named the schema


I haven't had a chance to work with it yet, so it may be full of bugs.

You need to name your ColdFusion data source flex2.

Wednesday, October 17, 2007

Mylyn works with Google Code

I just updated my copy of mylyn to the current version and I was happy to find that it now works easily with Google Code. In order to set it up, all you have to do is add a repository for the Google Code issue page. The easiest way to do this is to select the sample server entry for Google Code when adding the repository. All the necessary fields are filled in for you to make it work. Generally all you have to do is change the url is puts in the server field to point to your specific application. You don't get the fancy edit page that you would with something like Jira, but it will pull up the appropriate web page in eclipse's web browser. Pretty cool.

Also, if you hate that mylyn removes a file from context when you close it, there is a new check box in the settings that allow you to change that behavior.

Mylyn tends to be a little buggy out of the gate, but it eventually starts working as it should for me. Sometimes I have to move around the interface a few times to get things rolling after an update.

Wednesday, October 10, 2007


I've had a number of requests to explain DIAPER a little bit more since my last post, so I thought I would put a few thoughts here.

DIAPER is just an acronym for the sections I'm using in bean/vo style ColdFusion objects. These sections are:

Define: this is just a group of cfproperty tags that provide basic documentation for the object's properties. cfproperty doesn't really do anything in a programming sense for plain cf components, so I wouldn't normally do these if I wasn't using some sort of code generator or I was planning on handing off the actual coding to someone else instead of doing it myself. They provide a nice place to do a little documentation that gets picked up by numerous cfc introspection tools.

Initialize: This is your typical init() function that you use to get your component instance started. Mine almost always just start off with a list of cfarguments that match the "D" section above with all of the properties set to be not required and with a default. Following this, all of the arguments are assigned to a structure called "instance" that is stored in the variables scope. Using a structure of property values instead of just putting them into the variables scope individually is just a way to make them a little easier to use with some inspection utilities that I tend to use.

Access: These are your typical getter/setter functions that you see in lots of cfcs to provide access to private variables/properties. With DIAPER, though, the setters are changed into a "set", a "test" and a "do". This is done primarily to support unit testing and provide a way to circumvent your business rules. The way this works is that in normal operation, we call the set function as we normally would. It then does two things: 1) tests the value that you are trying to set against any business rules you may have for this property. Normally, I use lots of regular expressions here and use cfthrow to bail out of the function if the value doesn't pass. This can also get pretty complex when you do things like compare values with other components and queries. Lastly, the "do" function actually sets the value. Also having the "do" function allows you to bypass your business rules which can really come in handy with unit testing.

Pretty simple, really, but I wouldn't want to code all of this stuff by hand if I can avoid it.

Sean Corfield made a comment about how he is using the new onMissingMethod feature of cf8 in his work now. I really like the idea of eliminating some of the clutter that all these methods tend to put in my cfcs, so look for a new template eventually that will take advantage of that approach in cfcBlaster.

Print is pretty much a developer tool that lets you spit out the content of the component quickly. It is akin to the "toString" methods you see in so many other languages.

Equals lets you test two instances of a component to see if they are equal to each other. I don't find myself using this too often, so I still am not sure exactly what the best approach here is. If you want to use it to see if you have two handles on the same instance, then I would suggest adding a guid property to your component that is populated when you creat your instance. Then you can just compare those values. If on the other hand, you have a need to check if two instances are functionally equivalent, then the approach of serializing your properties and comparing the values seems to work. This area could use a little more testing, especially when dealing with aggregates.

Run is used to return an instance of the component with reasonable values in all of its properties. This is a big help with unit testing or testing your aggregate functions where you don't want to fire things into your db. It's roughly equivalent to a method that provides you with a mock object which can be tricky to get right using some of the unit testing frameworks.

A few things to keep in mind. cfcBlaster does not do anything with aggregates. You still need to code those yourself. In the accessor section of my components you will see "add" and "remove" methods that handle those. They get used extensively in my DAOs to populate components retrieved from the db that have parent/child relationships. Note that one of the interesting disconnects between objects and rdbms systems is that I never represent a many-to-many relationship in objects. I'm always dealing with one side of that or the other, unlike how that would be represented in the db.

Another thing to keep in mind is that DIAPER is all about your business logic (ie, it lives in your model). It doesn't deal with presentation at all, so if your set up with an MVC framework, these objects don't deal with controller or view issues at all.