<CFSCRIPT> Tag - ColdFusion


>> Return to CF Tag List

For the most part Coldfusion code is written in tags very similar to HTML. Inside of ColdFusion though Macromedia has added a Javascript like language called CFScript.

To delineate a block of CFScript you use the CFSCRIPT tag. It is very similar to the HTML <SCRIPT> tag. With CFSCRIPT though the script runs in the ColdFusion application server not locally in the web browser as normally Javascript does. In many cases, if you for example initialize three or more variables in CFScript it will run faster than the same operation in regular ColdFusion tags. In some cases it can make code easier to write as well!

Syntax:
     <CFSCRIPT>
          ...any valid ColdFusion script...
     </CFSCRIPT>



  <CFSCRIPT> Comments from Macromedia LiveDocsLiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
I think more examples of cfscript needed and explanation.

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
Nice script to zip files
<cfoutput>#zipFileNew("c:\zout.zip","c:\delete.txt")#</cfoutput>
<cfscript>
function zipFileNew(zipPath,toZip){

var output = createObject("java","java.io.FileOutputStream").init(zipPath);
var zipOutput = createObject("java","java.util.zip.ZipOutputStream").init(output);
var byteArray = repeatString(" ",1024).getBytes();
var input = "";
var zipEntry = "";
var len = 0;
var ii = 1;
var fileArray = arrayNew(1);
var directoriesToTraverse = arrayNew(1);
var directoryContents = "";
var fileObject = createObject("java","java.io.File").init(toZip);

if(fileObject.isDirectory())
arrayAppend(directoriesToTraverse,fileObject);
else
arrayAppend(fileArray,fileObject);

while(arrayLen(directoriesToTraverse))
{

directoryContents = directoriesToTraverse[1].listFiles();

for(ii = 1; ii LTE arrayLen(directoryContents); ii = ii + 1)
{

if(directoryContents[ii].isDirectory())
arrayAppend(directoriesToTraverse,directoryContents[ii]);
else
arrayAppend(fileArray,directoryContents[ii]);
}
arrayDeleteAt(directoriesToTraverse,1);
}



zipOutput.setLevel(9);

for(ii = 1; ii LTE arrayLen(fileArray); ii = ii + 1)
{

input = createObject("java","java.io.FileInputStream").init(fileArray[ii].getPath());
zipEntry = createObject("java","java.util.zip.ZipEntry").init(fileArray[ii].getPath());
zipOutput.putNextEntry(zipEntry);
len = input.read(byteArray);
while (len GT 0)
{
zipOutput.write(byteArray, 0, len);
len = input.read(byteArray);
}
zipOutput.closeEntry();
input.close();
}

zipOutput.close();

return "";
}
</cfscript>

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
What would be __really__ nice is if Macromedia made cfscript code ECMA compliant, as they have done with Actionscript and Javascript for Director!

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
It would be reeeeeally nice if these guys at Macromedia could modify the specification to allow the usage of NORMAL "=", "<=", ">=" INSIDE CFSCRIPT... Just leave the weird "lte", "neq" for CFML.

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
Response from Macromedia to er583:
You cannot use the cfquery tag, nor any other tag, in a CFScript.
ColdFusion MX users: for a list of functional equivalents to ColdFusion tags that you can use in a CFScript, see the scripting chapter in the "Developing ColdFusion MX Applications with CFML" book, at: http://livedocs.macromedia.com/cfmxdocs/Developing_ColdFusion_MX_Applications_with_CFML/CFScript.jsp

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
You cannot use CFML tags in CFScript

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
Can i cfquery inside a cfscript??

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
There should be a link to the script commands that can be executed inside cfscript. Especially the logical and flow control statements!

Thanks

LiveDocs Comments - coldfusion - 5.0 - CFML_Reference - Tags89.htm
I'd like to see more tags and example within <CFSCRIPT>.



[Top]


Recommended Books

[Top]

Web Sites

[Top]

Copyright © 2003- 2008, Orville Paul Chomer, All Rights Reserved