What is Scaffolding and How to use it - Part 3
If you read Part 2 of the series you might have seen Peter Bell's comment about the best way to use the code generated by scaffolding. Ok, so wouldn't it be great if the scaffolding was good enough to use without any change? Unfortunately the current templates available with the Fusebox scaffolder are likely to produce code that is less than complete. There are several areas where you will find it possible to improve the code. Lets look at each in turn because this situation is one where the answer may vary slightly in each case.
Peter suggested that you keep your changes outside the areas managed by the scaffolder. This is often possible because the CFCs that are generated the scaffolder puts comments around the generated code. As long as you restrict your changes to the areas outside the comments you can be sure that regenerating the code will not overwrite any changes you make. This is good when a new field gets added to an existing table. You can just regenerate the code for that table and it will overwrite the existing code with the new code.
In order to fully use this feature the code you write would have to be outside those comment blocks. In a CFC that is pretty easy. You can add methods to any of the generated CFCs knowing that only the methods within the comments are going to be changed. If you want full control over what happens when you call a method then you have to adopt a two step approach to the code. In that case another CFC extends the base CFC and allows the standard methods that have been generated to be overwritten. This is what happens in Doug Hughes' Reactor framework. Each CFC has another two CFCs which act to handle the calls first and override any method where the programmer wants to add extra functionality. The current Fusebox Scaffolding templates don't do that but I am thinking about adding that facility in a future release.
For CFCs, that's easy enough to implement, but it puts extra overhead in the system. What about the other things we generate like the circuit.xml and dsp_ fuses? Here things get more difficult. The circuit.xml has no built in mechanism for handling overrides. It is possible to generate a dummy fuseaction in each case that calls the real one with single do. The user would be allowed to edit and change the dummy to override what is going on. In fusebox 5.5 the answer might be to drop the xml and create a circuit CFC which will allow overrides. I am investigating that now and will let you know later what I discover.
The dsp_ files pose a more difficult problem, since the code is difficult to isolate into generated versus manually editable parts. I have a couple of ideas that I will discuss in a later posting, but they are based on the idea of creating a template in dreamweaver that can be merged with the generated code.
Of course there is another alternative which you might like to consider. Many people who develop serious applications are using CVS or Subversion as a version control system. If you are, you could create a branch on your version control system in which to save the generated code. Now make the changes and save them in a separate branch. When a change occurs to the database that requires you to regenerate the code you can use the facilities within your version control client to find the differences create a patch and apply it to your modified file.
Although this is a more tedious and awkward way to do things, in some circumstances it might be the best solution. I was thinking about that and it prompts another idea which is to check out the changes between the manually modified version and the original code. How easy is it to put those changes into the template?
Actually its very easy. The templates are written using ColdFusion so you don't have to know any special language to change the templates. There is documentation on how to do it with the scaffolder download. The only thing you need to decide is if the change is a generic one that should be applied to all the code generated by that template or just to a subset. I am considering some extra features in the generator to support passing parameters to the templates to allow these differences to be selectively turned on and off.
If you make an improvement tgo a template please send it to me for consideration as part of the standard offerings.
The scaffolder download (Alpha 1) is available right now on the fusebox site. Just download the extensions and read through the documentation and readme.txt to get started.


First issue was the extension download has your 'scaffolder' named 'scaffolding'
Second, templateDescriptor.cfm was failing on 'variables.datasource' and worked when changed to 'datasource'.
After running for a good bit, and successfully creating m_/v_/UDF's it hit the following error:
An error occurred when performing a file operation read on file C:\ColdFusion8\wwwroot\skeleton\traditional\scaffolder\templates\coldspring/Vo.as.
As you can see Im running this in a 100% fresh 5.5 skeleton app. Nothing special.
Im curious if you have a working version of the setup utilizing the Sean's skeleton\traditional app code?
Thanks in advance!
To get around these problems the best solution is to create a directory on your machine called scaffolder and use the Subversion repository to populate it.
http://svn.fuseboxframework.org/framework/branches...
Sean is updating his script to add the mssing files for the next release and I will fix the directory issue. In the meantime there are instructions in the latest readme file.
I guess this is what an alpha is all about. Thanks for reporting the issues.
I really think it would be helpful for you to place a true 'working' copy of your scaffolding within a working Fusebox 5.5 Skeleton Traditional within your repository.
Whadadaya Say?
Right now i'm extending the fusebox framework via the Application.cfc and I placed the scaffolder code in various places to try it: fusebox.init.cfm, fusebox.appinit.cfm with no luck. I'll try the index.cfm convention and see if it behaves at all.
Just a side note, and it may be mentioned in the documentation, but the scaffolder chokes on data type 'xml' which is new sql 2005.
Another bug that I noticed, perhaps its not a bug, but in MSSQL 2005, it seems to pick up the wrong database if the default database is set to master per say but in the coldfusion datasource, the correct database is specified. By passing the list of tables i was able to get around this weirdness.
Thanks for posting your experience. I will investigate the issue with application.cfc. Do you have an application.cfc that has an onRequest event?
Would it be possible for you to send your Application.cfc to me?