Learning ColdFusion 8: Javascript Object Notation (JSON) Part III - AJAX Demo

<cfcomponent
	output="false"
	hint="Handles some text utility functions.">
 
 
	<cffunction
		name="GetWords"
		access="remote"
		returntype="array"
		returnformat="json"
		output="false"
		hint="Returns an array of the words in the given string.">
 
		<!--- Define arguments. --->
		<cfargument
			name="Text"
			type="string"
			required="true"
			/>
 
		<!--- Define the local scope. --->
		<cfset var LOCAL = {} />
 
		<!---
			Get the words by splitting on non-word characters.
			This is not the best way to do this, but this is
			easy for the purposes of our demo.
		--->
		<cfset LOCAL.Words = ARGUMENTS.Text.Split(
			"[^\w]+"
			) />
 
 
		<!---
			ASSERT: Our words array here is not a traditional
			ColdFusion array. The String::Split() method gives
			us a Java string array which is not what a
			ColdFusion array actually is. Be CAREFUL!
		--->
 
 
		<!--- Create a standard ColdFusion array. --->
		<cfset LOCAL.Array = [] />
 
		<!---
			Add our Java string array to this ColdFusion
			array. To do this, we must convert the string
			array into a list.
		--->
		<cfset LOCAL.Array.AddAll(
			CreateObject( "java", "java.util.Arrays" ).AsList(
				LOCAL.Words
				)
			) />
 
 
		<!--- Return the ColdFusion array. --->
		<cfreturn LOCAL.Array />
	</cffunction>
 
</cfcomponent>

For Cut-and-Paste