Contents > Developing ColdFusion MX Applications > Integrating J2EE and Java Elements in CFML Applications > Using Java objects > Using basic object techniques Invoking objects PreviousNext

Invoking objects

The cfobject tag makes Java objects available in ColdFusion MX. It can access any Java class that is available on the JVM classpath or in either of the following locations:

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.


Contents > Developing ColdFusion MX Applications > Integrating J2EE and Java Elements in CFML Applications > Using Java objects > Using basic object techniques Invoking objects PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.