Calling Java Objects
The useExample CFML Page
The following useExample.cfm page uses the
strings, Booleans, and Example objects. Note the use of the
to ensure that CFML variables convert into the appropriate Java data types.
<html>
<head>
</head>
<body>
<!--- Create a reference to an Example object --->
<cfobject action=create type=java class=Example name=obj>
<!--- Create the object and initialize its public member to 5 --->
<cfset x=obj.init(JavaCast("int",5))>
<!--- Create an array and populate it with string values,
<cfset myarray=ArrayNew(1)>
<cfset myarray[1]="First">
<cfset myarray[2]="Second">
<cfset myarray[3]="Third">
<cfset ra=obj.ReverseStringArray(myarray)>
<!--- Display the results --->
<cfoutput>
</cfoutput>
<!--- Use the Java object to flip a Boolean value, reverse a string,
<cfset c=obj.Flip(true)>
<cfset StringVal=obj.ReverseString("This is a test")>
<cfset IntVal=obj.Add(JavaCast("int",20),JavaCast("int",30))>
<cfset FloatVal=obj.Add(JavaCast("float",2.56),JavaCast("float",3.51))>
<!--- Display the results --->
<cfoutput>
</cfoutput>
<title>CFOBJECT and Java Example</title>
then use the Java object to reverse them. --->
<br>
original array element 1: #myarray[1]#<br>
original array element 2: #myarray[2]#<br>
original array element 3: #myarray[3]#<br>
after reverse
element 1: #ra[1]#<br>
after reverse
element 2: #ra[2]#<br>
after reverse
element 3: #ra[3]#<br>
<br>
add two integers, and add two float numbers --->
<br>
StringVal: #StringVal#<br>
IntVal: #IntVal#<br>
FloatVal: #FloatVal#<br>
<br>
class to manipulate numbers,
Example
JavaCast
387
CFML function
Need help?
Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?