Using Java objects
You use the
cfobject
such as
and
cfset
(operations) on the object.
Method arguments and return values can be any valid Java type; for example, simple arrays and
objects. ColdFusion does the appropriate conversions when strings are passed as arguments, but
not when they are received as return values. For more information on type conversion issues, see
"Java and ColdFusion data type conversions" on page
The examples in the following sections assume that the
specified the value obj, and that the object has a property called Property, and methods called
Method1, Method2, and Method3.
Note: The cfdump tag displays an object's public methods and data.
Using basic object techniques
The following sections describe how to invoke Java objects.
Invoking objects
The
tag makes Java objects available in ColdFusion MX. It can access any Java class
cfobject
that is available on the JVM classpath or in either of the following locations:
•
In a Java archive (.jar) file in web_root/WEB-INF/lib
•
In a class (.class) file in web_root/WEB-INF/classes
For example:
<cfobject type="Java" class="MyClass" name="myObj">
Although the
cfobject
methods and fields are accessible immediately after the call to
If you call a public non-static method on the object without first calling the
ColdFusion makes an implicit call to the default constructor.
To call an object constructor explicitly, use the special ColdFusion
appropriate arguments after you use the
<cfobject type="Java" class="MyClass" name="myObj">
<cfset ret=myObj.init(arg1, arg2)>
Note: The init method is not a method of the object, but a ColdFusion identifier that calls the new
function on the class constructor. So, if a Java object has an init method, a name conflict exists and
you cannot call the object's init method.
To have persistent access to an object, you must use the
reference to an instance of the object, and
An object created using
the ColdFusion page execution.
746
Chapter 33: Integrating J2EE and Java Elements in CFML Applications
tag to create an instance of a Java object. You use other ColdFusion tags,
, or CFScript to invoke properties (attributes), and methods
cfoutput
tag loads the class, it does not create an instance object. Only static
cfobject tag
or returned by other objects is implicitly released at the end of
cfobject
751.
attribute in the
name
cfobject
; for example:
function, because it returns a
init
does not.
cfobject
tag
cfobject
.
method, there
init
method with the
init
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers