More XHTML Compliance Issues in ColdFusion 8
I ran into a problem recently where a completely valid XHTML 1.0 transitional site was rendered incompliant by the addition of <cfmenu>. It seems that <cfmenu> causes compliance to fail in two ways:
First, it adds JavaScript to the "OnMouseOver" and "OnMouseOut" attributes of its menu items. To be compliant, it should be adding them to the "onmouseover" and "onmouseout" attributes. There's an easy fix to this. Inspired by Ben Nadel's post on altering the output of the writeToBrowser feature of <cfimage> I just used <cfsavecontent> to capture the menu, and then alter it, as listed below:
<cfsavecontent variable="menuContent">
<cfmenu name="menu" type="vertical">
<cfmenuitem name="home" href="index.cfm" display="Home"/>
</cfmenu>
</cfsavecontent>
<!--- These calls help bring page to XHTML compliance. --->
<cfset menuContent = Replace(menuContent, "OnMouseOver", "onmouseover", "ALL") />
<cfset menuContent = Replace(menuContent, "OnMouseOut", "onmouseout", "ALL") />
<cfoutput>#menuContent#</cfoutput>
But that doesn't hit the other problem, which is that any of the Ajax capable tags seem to add the following bit of code to the top of a page:
_cf_loadingtexthtml="<div align='center'><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/>"
This screws up compliance on two fronts:
- The div created in that code isn't closed.
- The img created in that code doesn't have a alt tag.
Now the interesting thing here is that isn't actually a div that's created, it's only JavaScript that will at some point create those elements. I think technically the compliance test is falsely marking this as a violation. But try explaining that to a client who demands compliance without understanding the theory behind it.
Anyway, I can't find a single way around this. Using the OnRequest method of application.cfc was my best bet. I figured I would use to call <cfsavecontent> and replace the offending code like I did above. Unfortunately, this spot of code is directly written to the buffer when <cfmenu> gets called.
I also tried a few getPageContext() functions, but to no avail. I'll be stuck trying to explain this to the client. In the meantime, I filed a bug report with Adobe.
Comments
For now though I hope Adobe can fix validation issues fairly quickly, since the last thing we'd want is for some tags to become unusable in certain situations. Good post Terrence :)
We are working on the issue to add alt text with cfimage. We maybe posting a patch for this, but no promises.
@Terrence
I saw your wishlist posting and have logged a bug for the same. We will try to resolve it for the next release.
Please let us know any feedback/specific issues using
http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
so that we can review and track the issues.
Thanks, Hemant
I am curious as to what went wrong with the OnRequest and the CFSaveContent. Other than not being able to flush any of the content to the browser until the whole page has rendered, it should have worked. What CFMenu actually writing to the primary content buffer from within the CFSaveContent tag?
If enough of us start complaining about this, hopefully Adobe will do something about it!
BTW, I really liked the suggestion of using savecontent to fix some of the invalid code.
And regarding the "invalid" HTML in the JavaScript string. You are correct that it should not be flagged as invalid because technically it's just a string. But you're wrong in assuming that the validator is flawed. JavaScript code blocks should be nested inside CDATA tags (i.e. "// ") to tell the validator not to parse the contents of the script tags.
The other issue still stands. And I am so disappointed in Adobe for not fixing such a simple and important issue. One year on, it still exists!
Good post, Terrence.
@Hemant Thanks, the only issue I have with the wish form is that lack of feedback from it. I don't know if my replies go to the either or are being seen by someone. 


Posted by: Todd Rafferty at September 11, 2007 2:14 PM