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.

Comments
DaNGeR's Gravatar Just getting into scaffolding with the release of FB5.5 after a long road of fusebox. Downloaded all of the new code and extensions, but am hitting error after error. After making various changes to step over the errors I figured it was time to drop a comment.

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!
# Posted By DaNGeR | 10/15/07 3:22 AM
Kevin Roche's Gravatar Unfortunately there were a few inconsistencies between what I had on my machine and what got released, because of a couple of misunderstandings between me and Sean. Beacuse of that there are some missing files and the directory name changed from scaffolder to scaffolding.

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.
# Posted By Kevin Roche | 10/15/07 6:57 AM
DaNGer's Gravatar Still no such luck after obtaining straight from the repository, infact I cant even get it to work where as before I was able to.

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?
# Posted By DaNGer | 10/19/07 9:19 PM
Kevin Roche's Gravatar The download on the fusebox web site has been updated. Please try and again with that. If you have any problem then email the error message to me and I will do what I can to help. This is useful as its only by seeing these errors do I find my mistakes. I often find I have particular ways of doing things that mean what I do here works fine but when transported to another slightly different set up, falls over in heap. Let me know so I can fix it.
# Posted By Kevin Roche | 10/23/07 10:36 AM
Ben Koshy's Gravatar I too am having issues with the latest build from the SVN/Fusebox website. I changed the reference to scaffolder to scaffolding when invoking the component. It does get as far as writing the scaffolding.xml file but after that -- no generated templates seem to build and no error seems to be present.

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.
# Posted By Ben Koshy | 11/5/07 8:01 PM
Ben Koshy's Gravatar Quick followup. After changing its implementation not to use the application.cfc, and call fusebox from the index.cfm, it seemed to work much better.

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.
# Posted By Ben Koshy | 11/7/07 10:02 PM
Kevin Roche's Gravatar Ben,

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?
# Posted By Kevin Roche | 11/7/07 10:35 PM
Ben Koshy's Gravatar No I do not. If you read the latest scaffolding thread in the Fusebox 5 Yahoo Mailing List you'll see that Greg Luce also encountered a similar issue + a few new ones I didn't encounter. I'm still not sure if my scaffolder is generating my coldspring.xml
# Posted By Ben Koshy | 11/7/07 10:46 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.