Friday, October 04, 2002

Get CFMX Version of the CFML Reference to Studio and HomeSite+ Help Tab

If you're running CF4.5 or 5 of Studio, you may be interested in having the CFMX version of the CFML Reference available in the Help Reference Tab in Studio (Help>Help References Window). Also, folks running HomeSite+ may have noticed that there, too, the help reference doesn't include any CF manuals at all. Grr.

(I'm not referring here to the help shown when you press F1 on a tag or function, but instead the actual help tab listing several available books.)

Macromedia has solved the problem, at least a little. You can go to http://download.macromedia.com/pub/homesite/updates/cfml_ref.zip and download a zip file. Follow the instructions in the CFMLRef_install.txt file on where to install it and optionally how to improve its appearance inside the help tab once installed (by editing the booktree.xml file it talks about). This will cause you to have the CFMX version of the CFML Reference manual available in the help, but not the other CFMX manuals.

While the instructions apply to HomeSite+, they're equally applicable to previous releases of HomeSite and Studio. Try it!

BTW, if you're still using Studio 4.5 or 5 and want to update those, such as to add patches that came out after the product's release or to get tag help, insight and completion for CF 5 in Studio 4.5, those are all separate updates. See my blog entry of August 1 for more details.

How CFMX creates the filename for the compiled version of your CF code

In previous bog entries I've talked about compilation and precompilation of CFMX code into Java. And I've shared how all CF templates get compiled into the one [cfusionmx]\wwwroot\WEB-INF\cfclasses directory. 

Ever wonder how CF creates that file name? A CF template named Setsession.cfm might lead to a class file named cfsetsession2ecfm1011928409.class.  The "cf" is always there, while the next part is the file name and extension, but with "2e" where the period in the filename was. The number that follows represents a hash of the file/folder name.

Here are the details from Mike Nimer at Macromedia:
How CFMX creates the .class name, or how you can find the name of the .class file you want to delete

The formula is: "cf" + filename + hashCode

The fully canonicalized filename is used, with "/" as the directory separator. The following substitutions are made in the filename:
1.) / becomes __
2.) any other character which would be illegal in a Java identifier is represented as 2 hex digits

hashCode is the hashCode() of the File object which represents this file as documented at http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#hashCode()

If the hashCode() is negative, it is exclusive-OR'd with 0xFFFFFFFF to get the value used by ColdFusion.
It seems that hashcode call uses the filename AND the folder, as even two files in the same directory could end up with hashcode values that are different. 

You can prove this by creating two templates in the same folder, with distinctive names that you can readily identify, and then save and execute those pages, and view the latest class files created in the cfclasses folder. Those distinctively named files in the same folder may show having the same or different hashcodes. 

So sadly, this is like a one-way hash: cf can figure out what file exists in the cfclasses for a given filename/folder it wants to run, but we can't look at that hashcode and figure out what folder that file was in. At least we can see the name: though again you may well see many classes with the same name, for different folders in which a given filename may live. 

And note that for components (CFCs), note that there is a class for each method in that cfc (technically there is also a class for each cffunction in a cfm, as well). So you could have far more class files than you may expect if you somehow had an idea of how many cfm templates you had. :-)

Thursday, October 03, 2002

Pausing your CFMX code

Folks have often wanted to pause their CFcode, particularly when wanting to simulate some sort of long-running task. Usually they use a CFLOOP, but now that CMX is built upon Java, there is a better and less resource intensive way. Java has a "sleep" method in the java.lang.Thread object. You can get a wait by doing the equivalent:

<cfobject type="JAVA" name="obj" class="java.lang.Thread" action="CREATE">

<cfset obj.sleep(10000)>

This will pause 10 seconds.

CF_SLEEP

To make it even easier, I've created a custom tag to handle this, called cf_sleep. It's available both at the DevExchange and via my site. You would use it in the form:

<cf_sleep seconds="nn">

SLEEP UDF

It's also available as a UDF, in which you might use it in the form:

<cfinclude template="sleep_udf.cfm">
<cfset tmp=sleep(2)>

Believe it or not, this approach works in CF5 (and 4.5) as well as MX, since the ability to call Java objects was introduced back then.

Friday, September 27, 2002

Getting into Dreamweaver for Studio users

I know a lot of Studio uses are unhappy with Dreamweaver and inclined to just stay put, but maybe you're being forced by licensing issues or organization policy to make the move. Or maybe you just realize that the writing is on the wall so you might as well suck it up and make the most of it. I want to offer a couple thoughts that might make things a little more palatable. Perhaps these won't be news to you, but maybe they'll be useful resources.

First, Macromedia has put together a couple of resources to help this very audience. Four particular articles at the Dreamweaver Development Center deserve your attention:



Beyond that, there are several other articles at that site which show how to apply DW to various tasks that CF developers may be interested in (developing, using components and web services, for instance). There are are also tutorial examples (like the Trio Motor Company app) where they include source code and steps to finish the projects. All these are great ways to become familiar with really leveraging DWMX, rather than simply opening it up and lamenting "where is this, why can't I do that". OK, some things from Studio are missing or hard to find, but there are also things that DWMX adds that Studio doesn't have.

And DW is much more than the WYSIWYG html editor that basic web page developers liked so much for years. If you don't like it "mucking with your code", don't go into design mode. You can still leverage the database tools, site management features, and so much more.

Still, I know it's not perfect. Some people have reported real problems using it. Some factors relate to using certain features, or working in certain environments, or problems with resources and speed (a faster machine with more memory seems to temper those concerns). Anyway, Macromedia is listening and future updates will surely address our most grievous complaints.

In the meantime, Macromedia really didn't really leave us high and dry. For died in the wool Studio fans (or when things just don't work as you need them to in DWMX), did you know that the DWMX CD comes with a separately installable "HomeSite +"? HomeSite Plus is really nearly entirely the same as Studio 5. Even the CFML debugger is included (for those that leveraged that). Just install it and use either one. Indeed, there are easy means to go back and forth between them.

I recommend you install both and just try to work more and more in DW as you grow comfortable with it. I know many people tried a "cold turkey" approach to force themselves into DWMX. Why suffer the hassle? Use each while you become more familiar and comfortable with DWMX. You may even find that you grow to find it perfectly acceptable, even preferable.

Sure, for some this has been like being forced to write with their other hand. But we humans are amazingly capable of adapting. And Macromedia really is working to make it a more effective transition. At least give these resources 15 minutes reading before you conclude it just won't work for you, and for the things that just flat don't work, drop back to HomeSite+.

Not a sermon. Just a thought. :-)