Copy link to clipboard
Copied
This question was posted in response to the following article: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f14.html
Copy link to clipboard
Copied
You cannot sort an array that is returned by a java object. CF errors out. You will have to create a new array and loop-and-append to it then sort your array. Like so
<cfset timezoneClass = createObject( "java", "java.util.TimeZone" ) />
<cfset timezoneIDs = timezoneClass.getAvailableIDs()>
<!--- THIS FAILS --->
<cfset arraysort(timezones,"textnocase")>
<!--- THIS SUCCEEDS --->
<cfset timezones = arraynew(1)>
<cfloop array="#timezoneIDs#" index="tzid" >
<cfset arrayappend(timezones,tzid)>
</cfloop>
<cfset arraysort(timezones,"textnocase")>
Copy link to clipboard
Copied
Curious. In your first example, you set timezoneClass and timezoneIDs, but then try to sort timezones (which, AFAICS, you didn't set.)
^_^
Copy link to clipboard
Copied
Should have been
<cfset timezoneClass = createObject( "java", "java.util.TimeZone" ) />
<cfset timezoneIDs = timezoneClass.getAvailableIDs()>
<!--- THIS FAILS --->
<cfset arraysort(timezoneIDs,"textnocase")>
<!--- THIS SUCCEEDS --->
<cfset timezones = arraynew(1)>
<cfloop array="#timezoneIDs#" index="tzid" >
<cfset arrayappend(timezones,tzid)>
</cfloop>
<cfset arraysort(timezones,"textnocase")>
Copy link to clipboard
Copied
Coldfusion arrays are not Java arrays, but Vector Lists: http://www.bennadel.com/blog/1030-Building-Java-Arrays-In-ColdFusion-Using-Reflection.htm
If you want to sort a Java array, use array.sort(): http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Arrays.html