Adobe COLDFUSION 9 Manual page 1166

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Working with complex .NET data types
When you use complex .NET data such as Hashtable, ArrayList and DataTable, ColdFusion normally automatically
converts the data to the corresponding ColdFusion data type: structure, array, and query, respectively. When you work
with this data you take specific actions to enable the proper access and conversion of the data, as follows:
• Use associative array notation to properly access .NET Hashtable data from ColdFusion
• You cannot use ColdFusion variables directly in parameters that take Hashtable, ArrayList, or DataTable input.
• You can disable automatic conversion of complex .NET data to ColdFusion types.
• You can manually convert complex .NET data to ColdFusion types.
Using Hashtable data in ColdFusion
.NET Hashtables are case sensitive, but most methods of ColdFusion structure access are not case sensitive. Only
associative array notation of the form structName
converted to CF structure, the entire data set is converted, even if the element keys differ only in case. Therefore, to get
the values of the keys that differ only in case, use associative array notation.
The following example shows this issue. It creates a Hashtable object with three entries whose key values vary only in
case. In the example, output using dot-delimited structure notation always returns the same value, corresponding to
the all-uppercase key, but associative array notation returns the correct result.
<!--- Create a Hashtable and convert it to a ColdFusion structure. --->
<cfset table = createObject(".NET", "System.Collections.Hashtable")>
<cfset table.add("Key", "Value1")>
<cfset table.add("KEY", "Value2")>
<cfset table.add("key", "Value3")>
<cfset cftable = DotNetToCFType(table)>
<cfdump var="#cftable#">
<h3>Using dot notation</h3>
Key : <cfoutput>#cftable.Key#</cfoutput><br>
KEY : <cfoutput>#cftable.KEY#</cfoutput><br>
key : <cfoutput>#cftable.key#</cfoutput><br>
<p>
<h3>Using associative array notation</h3>
Key : <cfoutput>#cftable["Key"]#</cfoutput><br>
KEY : <cfoutput>#cftable["KEY"]#</cfoutput><br>
key : <cfoutput>#cftable["key"]#</cfoutput><br>
Using .Net ArrayList in ColdFusion
ColdFusion converts System.Collections.ArrayList objects to ColdFusion arrays, and you can perform all standard
ColdFusion array operations on them. The following example shows this usage:
.Net Code:
public ArrayList getList(){
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add(1);
myAL.add(true);
Return AL;
}
keyName
is case sensitive. When .NET Hashtables are
["
"]
Last updated 8/5/2010
1161

Advertisement

Table of Contents
loading

Table of Contents