Remote Synthesis
Search my blog:
Viewing By Entry / Main
Nov 19, 2006

Generate ColdFusion Code Powered by Flex

Part of my new job includes doing some Flex development with Cairngorm, neither of which I had used previously. So, as a learning experience, I decided to rewrite my Illudium PU-36 Code Generator with Flex UI. I am releasing this as the new version of the code generator, but initially as an alpha so I can get some testing. What this means is you can get it via subversion in the branches folder or via the download link on this post.Install Instructions
All you should need to do is:

1) Download the files and place them in a folder on your web root (if the folder is not named cfcgenerator, you will need a mapping with that name);

2) Open Application.cfm and change the value of adminPass to your ColdFusion Administrator password.

That's it. The ColdFusion components are kept in application scope, so if you make any changes after you load the app, just append ?reload=true to the URL. Remember that the Flex/ColdFusion communication requires ColdFusion 7.0.2. Also remember this is alpha software :)

Using the Generator and New Features
Using the generator should be pretty intuitive. When the app loads it will populate a list of all the supported DSNs (currently MSSQL, Mysql - 5.0 only I think as it was never tested on 4.1 - and Oracle). It will then load a list of tables within the preselected dsn. Lastly, it loads the included templates (currently the default, prototype - just a copy of default intended to be customized, and Transfer). This leads me to one of the main new features, you can switch templates on the fly rather than have them tied to a dsn as before.

Once you have made your DSN selection, and the table and template you want to generate against, you simply put the path to the cfcs in the path field. So if you were generating user components under the /com/user directory and your user bean will be named user.cfc, enter "com.user.user". Now just click generate and the tabs should populate on the right with the code for you to copy/paste into your IDE. Pretty damn easy right?

There is one other option, which is to remove extra line breaks. I am not sure why this occurs but in some cases the code appears with extra line breaks. If so, just select this option and they will be removed for you (you will need to re-click on the "generate" button).

Looking at the Code
Just a side note, but part of making my code work nicely with Flex and Cairngorm (including the automatic conversion of component to value object) meant a pretty substantial refactoring of my cfcs, but it made a much stronger design IMO. I actually did have the HTML version using this, but I never got around to releasing it. The nice thing was that I was able to get the app down to only only a handful of service methods, and the code is much more flexible I believe now.

I also intend to also release the mxml when I do the final release of the project so that people can edit the actual Flex code (this is open source after all).

Looking for Feedback
I had a handful of testers help me this weekend so that I could feel comfortable releasing this. I did have one user who had a problem with the install when it required a mapping. It did eventually work, but I would like some feedback on that. Also, would love feedback on the new features or any feature suggestions. Lastly, I have heard most users are modifying the XSL templates, which is great and what I intended. I would love it, if you have done this, if you would share your templates and we could make a library of them so that people could add them as options to their templates menu. So email me if you would like to share your templates with the project.

Download the attachment.

Comments
Joe Rinehart
This is ironic...I'm sitting here using the old version to generate AS3 code!

Looking forward to the new version, Brian - I've gotten a lot of mileage out of the existing one for places where Reactor won't do.


Brian Rinaldi
Sweet! Any chance you'd be willing to share your AS3 templates? :)

Also, sorry, the code zip has been added to the post. It can also be downloaded from Subversion.


Josen Ruiseco
After changing the admin password I loaded the page and got two sets of three errors:

Send failed
Client.Error.MessageSend
Fault occured in GetTemplateCommand

Send failed
Client.Error.MessageSend
Fault occured in GetTemplateCommand

I had to press okay 6 times to get to the app. At that point I had nothing loaded in the interface.

Any ideas what I am doing wrong?

Josen


Brian Rinaldi
That sounds like the error you get if you are not running ColdFusion 7.0.2. Could that be the issue?


Josen Ruiseco
ColdFusion 7.0.2 is up and running...


Rob
Hi,
thanks for the generator.
I' downloaded the code generator into the webroot: http://localhost:8500/cfcgenerator/index.cfm

Changed the password and appended the ?reload=true var.
and still keep getting an error:
=====================
<code>

RangeError: Index '0' specified is out of bounds.
   at mx.collections::ListCollectionView/getItemAt()
   at mx.collections::ListCollectionView/http://www.adobe.com/2006/actionscript/flash/proxy::getProperty()
   at com.commands::GetDatasourcesCommand/result()
   at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()
   at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()
   at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
   at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
   at mx.rpc::Responder/result()
   at mx.rpc::AsyncRequest/acknowledge()
   at ::NetConnectionMessageResponder/NetConnectionChannel.as$37:NetConnectionMessageResponder::resultHandler()
   at mx.messaging::MessageResponder/result()

</code>
=============================
Any idea what could be the issue.

Installed:
Windows 2k server
ColdFusion 7.0.2


~Cheers


Brian Rinaldi
Could it be that you don't have any supported datasources (MSSQL,MySQL,Oracle)? That is an unhandled error at this point in my code (which I will try to correct shortly). Basically, after loading the DSNs it sets the first item as the selected item and then loads the tables. What appears to be failing is when it tries to select the first item on an array with no elements.


Rob
Humm;
I got MSSQL 2K, Windows 2k server and ColdFusion 7.0.2 installed.
I get the error using Firefox or Opera but not error when using IE. But still the no DNS on the drop down selection in any browser.

Could it be that I'm using 2k Windows server?

Anyway, thanks again

~Cheers


Brian Rinaldi
In the folder /com/cf/model/ there is a test.cfm file which is just a scratchpad for testing the CF code. Try running this line there and let me know what it tells you:

<cfdump var="#createObject('component','cfcgeneratorFlex.com.cf.model.generatorRemote').getDSNs()#">


Brian Rinaldi
Sorry, that line should be (wrong path info):

<cfdump var="#createObject('component','cfcgenerator.com.cf.model.generatorRemote').getDSNs()#">


Nick
Any chance you could post a quick tutorial or primer to using the code generated with this app with a Cairngorm 2 Flex app?

For example, the code generator creates the coldspring XML configuration file. Now, I've only ecently become aware of ColdSpring, so I'm not entirely sure how I need to use this with a Flex app, or if I use it at all and just use RemoteObject to talk directly to the service CFCs.

Any help you can offer would be appreciated.


Brian Rinaldi
Note to those having issues, my mention of using a mapping rather than the "/cfcgenerator" file location may not work out of the box. Thanks to Todd Sharp for the tip, but apparently to use a CF mapping you would need to edit your wwwroot\web-inf\flex\services-config.xml and set <use-mappings>true</use-mappings> (it is apparently false by default). Let me know if this solves the issues.

Nick, the generator uses Flex and Cairngorm but does not currently (unless anyone has any templates to donate :) generate code specifically for use *with* Flex or Cairngorm. You could use the generated CF code as the back-end to a Flex app however...the only change that would be necessary would be to add some cfproperty tags to the generated beans (a change that I intend to make soon).


todd sharp
Just subscribing...if the setting fixes the problem please post it in the comments here!


Aaron Rouse
I just tried downloading it and put it into my webroot under a directory named cfcgenerator. I changed the admin password and then tried loading it up in the web browser. I get an error that states "The value returned from function getTables() is not of type query." click OK to that then get another box that says "Server, Processing" then click OK to that and get another box and it says "Fault occured in GetTablesCommand." then I click OK to that and am in the app. The DSN drop down lists the few DSNs I have setup on this box and if I click on the Table it is empty. If I change the DSN then I go through those same three errors. All of my DSNs are connecting to Oracle databases, one is XE(10g) running on my localhost and the other two are 9i running on another box.

Is Mach-II still needed for this? I do not have it on this box is why I ask and recall it being needed for the other version.


Brian Rinaldi
Aaron, thanks for pointing this out, it is a minor bug in com/cf/model/datasource/oracle.cfc - the method getTables() beginning on line 10 still has a returntype from the old version of the app. If you change that from query to array, it should fix the issues you mention. I will commit that change in svn (under branches > Flex Version) this evening and post up a new zip in this and the recent update (http://www.remotesynthesis.com/blog/index.cfm/2006/11/24/Updates-to-Flex-Powered-Code-Generator). Just in case you didn't catch that post, I recommend updating to the new version (though that error will exist there as well until I get the chance to fix it tonight)


Aaron Rouse
Thanks, changing that line got rid of the errors. I did not see your other post earlier and had just downloaded the latest copy from the Google code site.

Now that it is working I notice that the Oracle queries are pulling out tables that are outside of the default tablespace for that user used for the DSN connection. Just off the top of my head if the owner is not needed then this query I think would return table names for the default table space:

SELECT DISTINCT TNAME TABLE_NAME, 'TABLE' TABLE_TYPE FROM COL

It at least seems to work with that in my minimal testing.


Adam Howitt
Hey Brian,
Any fix for the send failed message listed earlier by Josen. I'm running developer edition CF 7.0.2 with multiple instances of CF. The test.cfm dump you mentioned earlier returns an array of five datasources which sounds right. I have used this introspection before so I know I have the password right etc. Is there some kind of flash security setting or how do I debug this? Thanks for your contribution to the community.
Adam


Brian Rinaldi
Adam, I have had one report from someone that downloaded a copy that had some incorrect component calls calling cfcgeneratorFlex and not cfcgenerator. A couple others realized that it was the Flex/CF communication that was failing generally and not specifically within this application (a reinstall of 7.0.2 fixed that and I know that isn't an easy solution).

Also,hHave you pulled the latest version from RIAForge or Google Code?


Marco
Hi Brian. Congratulations for cfcgenerator. Looks like a great saver time for us! But..... do you have any simple example about how to use gateway and beans generated by cfcgenerator? Cheers


Dave Anderson
I'm getting the ol' 'Send Failed' error when trying to run the Illudium PU-36 Code Generator ('Where's the kaboom?').

Oddly, I had it running not long ago. I believe I had to reinstall CF since the last time I saw it running, but I am updated to 7.02. I checked the flex config file and set use-mappings to true.

In attempting to diagnose the nature of my problem, I instantiated an adminAPIfacade. No problem there. I called its getDatasources() method. No problem there. When I instantiate the generatorRemote cfc and call its getDSNs() method, I get the following error:

Element ADMINAPIFACADE is undefined in a Java object of type class [Ljava.lang.String; referenced as

It points me to line 31 of the generatorService.cfc, which is the getDSNs function. All it does is call the adminAPIfacade's getDatasources() function, which I seem to be able to run just fine outside the generatorService.

Any clues as to what's going on here? I need to disintegrate some varmants!


Brian Rinaldi
@Marco, I don't have examples of using the code yet, but I am hosting a presentation through cfframeworks.com that will go over some. Remember though, the intent is for you to make the code whatever you wish by tweaking the templates.

@Dave, The CF error you list sounds like simply that the application scope isn't in the application scope (since the remote facade uses the app scoped services).

I wouldn't spend to much time focusing on the CF since the error you get is a send failed, which is a Flex error (the other ones look like "Error occurred in getDatasourcesCommand" or something along those lines). The send failed seems to be exclusively a communication issue between Flex and CF. I am not sure where the issue would be as this is typically if CF isn't at 7.0.2 or a the mapping issue (you have a CF mapping called "cfcgenerator"?). Feel free to email me offline and I will do my best to help.


Brian Rinaldi
Ugh. Silly me. A better forum for these issues would be the mailing list at http://groups.google.com/group/cfcgenerator (I get and respond to those as well).


Write your comment



(it will not be displayed)