Lets you create and use JAVA objects, and by extension EJB objects.
<cfobject action = "Create" type = "Java" class = "Java class" name = "object name">
cfcollection,
cfexecute,
cfgraph,
cfindex,
cfreport,
cfsearch,
cfservlet,
cfwddx
To call Java CFXs or Java objects, ColdFusion uses a JVM embedded in the process. The JVM loading, location and settings are configurable using the ColdFusion Administrator pages.
Any Java class available in the class path specified in the ColdFusion Administrator can be loaded and used from ColdFusion using the cfobject
tag.
Use the following steps to access Java methods and fields:
cfobject
to load the class. See 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, arrays, objects). ColdFusion does the appropriate conversions when strings are passed as arguments, but not when they are received as return values.
Overloaded methods are supported if the number of arguments is different. Future enhancements will let you use cast functions to allow method signatures to be built more accurately.
To create and call EJB objects, use cfobject
. The sequence in the second example assumes that the WebLogic JNDI is used to register and find EJBHome instances.
<!--------------------------------------------------------------------- Example of a Java Object This cfobject call loads the class MyClass but does not create an instance object. Static methods and fields are accessible after a call to cfobject. ----------------------------------------------------------------------> <cfobject action = "create" type = "Java" class = "myClass" name = "myObj">
<!--------------------------------------------------------------------- Example of an EJB The cfobject tag creates the Weblogic Environment object, which is then used to get the InitialContext. The context object is used to look up the EJBHome interface. The call to create() results in getting an instance of stateless session EJB. ----------------------------------------------------------------------> <cfobject action = "create" type = "JAVA" class = "weblogic/jndi/Environment" name = "wlEnv"> <cfset ctx = wlEnv.getInitialContext()> <cfset ejbHome = ctx.lookup("statelessSession.TraderHome")> <cfset trader = ejbHome.Create()> <cfset value = trader.shareValue(20, 55.45)> <cfoutput> Share value = #value# </cfoutput> <cfset value = trader.remove()>