User Guide

Table Of Contents
Using Java objects 929
For example:
<cfobject type="Java" class="MyClass" name="myObj">
Although the cfobject tag loads the class, it does not create an instance object. Only static
methods and fields are accessible immediately after the call to
cfobject.
If you call a public non-static method on the object without first calling the
init method, there
ColdFusion makes an implicit call to the default constructor.
To call an object constructor explicitly, use the special ColdFusion
init method with the
appropriate arguments after you use the
cfobject tag; for example:
<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 init function, because it returns a
reference to an instance of the object, and
cfobject does not.
An object created using
cfobject or returned by other objects is implicitly released at the end of
the ColdFusion page 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 the following “Calling JavaBean get and set methods section.
To set a property:
<cfset obj.property = "somevalue">
To get a property:
<cfset value = obj.property>
Note: ColdFusion does not require that property and method names be consistently capitalized.
However, you should use the same case in ColdFusion as you do in Java to ensure consistency.
Calling methods
Object methods usually take zero or more arguments. Some methods return values, while others
might not. Use the following techniques to call methods:
If the method has no arguments, follow the method name with empty parentheses, as in the
following
cfset tag:
<cfset retVal = obj.Method1()>