Adobe COLDFUSION 9 Manual page 1140

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Using Java objects
You use the cfobject tag to create an instance of a Java object. You use other ColdFusion tags, such as cfset and
, or CFScript to invoke properties (attributes), and methods (operations) on the object.
cfoutput
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
page 1139.
The examples in this discussion assume that the
the object has a property called Property, and methods called Method1, Method2, and Method3.
Note: The
tag displays the public methods and data of an object.
cfdump
Using basic object techniques
You can use ColdFusion to invoke Java objects and access object methods and properties.
Invoking objects
The
tag makes Java objects available in ColdFusion. It can access any Java class that is available on the JVM
cfobject
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
tag loads the class, it does not create an instance object. Only static methods and fields are
cfobject
accessible immediately after the call to
If you call a public non-static method on the object without first calling the
implicit call to the default constructor.
To call an object constructor explicitly, use the special ColdFusion
you use the
tag; for example:
cfobject
<cfobject type="Java" class="MyClass" name="myObj">
<cfset ret=myObj.init(arg1, arg2)>
Note: The
method is not a method of the object, but a ColdFusion identifier that calls the
init
constructor. So, if a Java object has an
To have persistent access to an object, use the
and
does not.
cfobject
An object created using
cfobject
execution.
Using properties
Use the following coding syntax to access properties if the object does either of the following actions:
• Exposes the properties as public properties.
• Does not make the properties public, but is a JavaBean that provides public getter and setter methods of the form
getPropertyName() and setPropertyName(value). For more information, see
methods" on page 1136.
"Java and ColdFusion data type
attribute in the
name
.
cfobject
method, a name conflict exists and you cannot call the object
init
function, because it returns a reference to an instance of the object,
init
or returned by other objects is implicitly released at the end of the ColdFusion page
Last updated 8/5/2010
conversions" on
tag specified the value obj, and that
cfobject
method, ColdFusion makes an
init
method with the appropriate arguments after
init
new
"Calling JavaBean get and set
1135
function on the class
method.
init

Advertisement

Table of Contents
loading

Table of Contents