User Guide
318 Chapter 2: ColdFusion Tags
cfobject: Java or EJB object
Description
Creates and manipulates a Java and Enterprise Java Bean (EJB) object.
Syntax
<cfobject
type = "Java"
action = "Create"
class = "Java class"
name = "object name">
See also
cfcollection
, cfexecute, cfindex, cfreport, cfsearch, cfwddx; “Using Java objects” in
Chapter 37, “Integrating J2EE and Java Elements in CFML Applications,” in ColdFusion MX
Developer’s Guide
Attributes
Usage
To call Java CFXs or Java objects, ColdFusion uses a Java Virtual Machine (JVM) that is
embedded in the process. You can configure JVM loading, location and settings in the
ColdFusion Administrator.
Any Java class available in the class path that is specified in the ColdFusion Administrator can be
loaded and used from ColdFusion, using the
cfobject tag.
To access Java methods and fields, do the following steps:
1.
Call the cfobject tag, to load the class. See the example code.
2.
Use the init method with appropriate arguments, to call a constructor. For example:
<cfset ret = myObj.init(arg1, arg2)>
Calling a public method on the object without first calling the init method results in an implicit
call to the default constructor. Arguments and return values can be any Java type (simple, array,
object). ColdFusion makes the conversions if strings are passed as arguments, but not if they are
received as return values.
Overloaded methods are supported if the number of arguments is different.
Attribute Req/Opt Default Description
type Optional Object type:
• com
• corba
• java
(The other object types do not take the
type attribute.)
action Required Create: Creates a Java or WebLogic Environment object.
class Required Java class.
name Required String; name for the instantiated component.