dans.blog


The miscellaneous ramblings and thoughts of Dan G. Switzer, II

Disabling Auto-Complete For Certain Fields

Have you ever wanted to turn off Internet Explorer's "auto-complete" feature for a specific form field? Well, there's a lesser known, IE-specific, attribute named "autocomplete" for the <input> tag which will disable the auto-complete drop down box from appearing. Why would you want to do that, well there's lots of reasons. Maybe your creating a site geared towards public computers that allow a user logon; in that case, you don't want user names appearing in the autocomplete box.

To disable the auto-complete feature, just add the "autocomplete" attribute to your form field tags with the value of "off". For example:

<input type="text" name="userId" autocomplete="off" />

more…


Open Source Code Ultimately Better?

Reasoning recently did a review of Apache's code and found that the defects per thousand lines of code were on par with commercial products in the same stage of development. Although the number of defects were slightly higher (by .02 per thousand lines of code,) Reasoning determined that the end result may turn out to be a better product due to the nature of open source projects—implying that bugs found are more likely to be addressed quickly by the public, since anyone has the ability to track down and repair the bugs.

"The open-source code seems to start at the same defect rate for early commercial code as well," Jeff Klagenberg, director of project management, said in an interview. "Over time, it can gain higher levels of quality. That appears to be because of the natural inspection process inherent in open source."

I hate to see blanket statements like this. I do think when an open source project has financial backing by a large company, that this probably holds true, but let's face it, there's only so much energy someone will put into a open source project before needing some kind of monetary return.

more…


Creating Dynamic "onload" Events Using JavaScript

I posted a new article to PengoWorks.com today that shows a technique for running multiple onload events without altering your base source code. Here's a quote:

One of the most common things I run into while developing sites dependant on JavaScript is the need to have multiple operations run during <body>'s onload event. I think this is a problem most developers run into, since it's very common to develop a set of "shared border" templates that render the shell of your site and the body of your document is included via a server-side command.

Often you have the need to invoke some JavaScript during the onload event of every page. This might be to render a DHTML-based menu, or simply to initial some information about the page, regardless, you need this information to run on every page.

However, you often run into the case were you need to run some addition commands based upon the page that's being inserted. Most often this happens when I'm developing a page that has a form on it. There are a lot of ways to tackle this problem, but the tip I'm going to share with you is the one that I've found over the years to be the best solution. For a lack of a better term, I'll call this the "Auto-init()" method.

If you have any comments about the article, please post a comment!


UDF: component() for CFMX

Have you ever had the need to invoke an instance of a componet based upon it's relative path? I know I have, so I threw this little UDF together.

To invoke a component, you simply call the component() function using either the standard dot notation or you can specify either a relative or absolute path to the CFC. I tried to make the "type" argument somewhat intelligent and it'll probably work correctly 99% of the time for you, but if you want to be absolutely sure you get the expected behavior, specify the type argument for the function.

/****************************************************************
UDF: component(path, type)
Author: Dan G. Switzer, II
Date: 5/26/2004

Arguments:
path - the path to the component. can be standard
dot notation, relative path or absolute path
type - the type of path specified. "component" uses
the standard CF dot notation. "relative" uses
a relative path the the CFC (including file
extension.) "absolute" indicates your using
the direct OS path to the CFC. By default
this tag will either be set to "component"
(if no dots or no slashes and dots are found)
or it'll be set to "relative". As a shortcut,
you can use just the first letter of the type.
(i.e. "c" for "component, etc.)
Notes:
This is based upon some code that has floated around the
different CF lists.
****************************************************************/

function component(path){
    var sPath=Arguments.path;var oProxy="";var oFile="";var sType="";var sProxyPath = "";
    if( arrayLen(Arguments) gt 1 ) sType = lCase(Arguments[2]);

    // determine a default type
    if( len(sType) eq 0 ){
        if( (sPath DOES NOT CONTAIN ".") OR ((sPath CONTAINS ".") AND (sPath DOES NOT CONTAIN "/") AND (sPath DOES NOT CONTAIN "\")) ) sType = "component";
        else sType = "relative";
    }

    // create the component
    switch( left(sType,1) ){
        case "c":
            return createObject("component", sPath);
        break;

        default:
            if( left(sType, 1) neq "a" ) sPath = expandPath(sPath);
            // updated to work w/CFMX v6.1 and v6.0
            // if this code breaks, MACR has either moved the TemplateProxy
            // again or simply prevented it from being publically accessed
            if( left(server.coldFusion.productVersion, 3) eq "6,0") sProxyPath = "coldfusion.runtime.TemplateProxy";
            else sProxyPath = "coldfusion.runtime.TemplateProxyFactory";
            try {
                oProxy = createObject("java", sProxyPath);
                oFile = createObject("java", "java.io.File");
                oFile.init(sPath);
                return oProxy.resolveFile(getPageContext(), oFile);
            }
            catch(Any exception){
                writeOutput("An error occured initializing the component #arguments.path#.");
                return;
            }
        break;
    }
}

more…


UDF: xslt() for CFMX

I wrote this CFMX-based UDF a while ago, and I thought I'd share it. One of my big gripes about the xslTransform() function in CFMX is that it doesn't support passing parameters to the transformation engine.

Passing parameters can be extremely useful, as it'll allow you to do some conditional operations on in your XSL sheets based upon values determined by the ColdFusion.

In a nutshell, this UDF accomplish this by parsing the XSL stylesheet and looking for instances of the <xsl:param> tag name attributes that match the key in the structure you passed in. Once it's looped through the entire "Params" structure, it'll use the modified XSL stylesheet to do the transformation. Basically, it just temporarily hard codes those values in the param for you.

more…