Friday, November 30, 2012

New Structure Declaration in ColdFusion 10

In ColdFusion 10 a new structure declaration type is introduced.  This is very similar to JavaScript Object declaration and it is as follows:



Here we are using colon as separator between key and value rather than '='. Above I have mentioned keys as case sensitive. This means not case sensitive to ColdFusion but other technology like JavaScript.(If we are returning this structure by any AJAX call)

Wednesday, November 28, 2012

Setting Cookie by cfscript in ColdFusion 10

Now a days in ColdFusion coding most of us generally using script version of CF more than tag version. Sometimes we feel upset when we don't get the script version for a particular tag. In  such cases we write our own function to use that in script code. CFCOOKIE is one tag which used to set cookie and which doesn't have any script version before ColdFusion 10.

   In ColdFusion 10, script version for CFCOOKIE  introduced. We can set cookie by cfscript in ColdFusion 10 as follows.


In the above code two ways are quite similar, here we are creating a structure where the key of the structure is exactly same as the attributes of the cfcookie tag. If we are using cfscript  to set cookie then we don't need to set name of the cookie in the structure as we usually do for cfcookie.

Also in ColdFusion 10, two new attributes added for setting cookie. These are follows:

preserveCase : Specify if you want to make cookie name case sensitive. This is an optional parameter and default value is "false."

encodeValue : Specify if cookie value should be encoded. This is an optional parameter and default value is "false".

Hope it will help you.

Wednesday, November 21, 2012

For-In Loop Over query and struct object

After a long gap now I got some time for my own blog.

Recently I just studied few new functionality which has been added in ColdFusion 10. For-in loop one of the functionality liked.

Lets take a look into the following code to use for-in loop for looping over any structure or any query object.

<cfscript>
    //Create an Query Object
    qryEmployeeList = queryNew("empID, firstName, lastName", "BigInt, VarChar, VarChar");
    queryAddRow(qryEmployeeList, 2);
    querySetCell(qryEmployeeList, "empID", 1, 1);
    querySetCell(qryEmployeeList, "firstName", "Sachin", 1);
    querySetCell(qryEmployeeList, "lastName", "Tendulkar", 1);

    querySetCell(qryEmployeeList, "empID", 2, 2);
    querySetCell(qryEmployeeList, "firstName", "Rahul", 2);
    querySetCell(qryEmployeeList, "lastName", "Dravid", 2);

    //Create Struct
    strEmployeeInfo = structNew();
    strEmployeeInfo['empID'] = "3";
    strEmployeeInfo['firstName'] = "Saurav";
    strEmployeeInfo['lastName'] = "Ganguly";

    //Loop Over Query Object using for in
    for( employee in qryEmployeeList) {
        WriteOutPut(employee.empID & " : " & employee.firstName & " " & employee.lastName & "<br/>");
    }

    //Loop Over struct Object using for in
    for(strfieldName in strEmployeeInfo) {
        WriteOutPut(strfieldName & " : " & structFind(strEmployeeInfo, strfieldName) & "<br/>");
    }
</cfscript>

Happy Coding. Lets wait for some new interesting things in ColdFusion 10.

Followers