<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFOBJECT: JAVA OR EJB OBJECT</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">CFOBJECT: JAVA OR EJB OBJECT</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Creates and manipulates a Java and Enterprise Java Bean (EJB) object. 
</p>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="syntax"><span class="title">Syntax</span><pre>&lt;cfobject 
   type = &quot;Java&quot;
   action = &quot;Create&quot;
   class = &quot;Java class&quot;
   name = &quot;object name&quot;&gt;
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
cfcollection, cfexecute, cfindex, cfreport, cfsearch, cfwddx; "Using Java objects" in Chapter&#160;37, "Integrating J2EE and Java Elements in CFML Applications," in ColdFusion MX Developer's Guide
</p>

<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
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.
</p>

<p>
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.
</p>

<p>
To access Java methods and fields, do the following steps:
</p>
<ol type="1">

<li>Call the cfobject tag, to load the class. See the example code.</li>

<li>Use the init method with appropriate arguments, to call a constructor. For example:</li>
<pre>&lt;cfset ret = myObj.init(arg1, arg2)&gt;
</pre></ol>

<p>
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.
</p>

<p>
Overloaded methods are supported if the number of arguments is different. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Calling EJBs</span>
<p>
To create and call EJB objects, use the cfobject tag. In the second example below, the WebLogic JNDI is used to register and find EJBHome instances.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;!--- 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. ---&gt;
&lt;cfobject 
   action = &quot;create&quot;
   type = &quot;java&quot;
   class = &quot;myclass&quot;
   name = &quot;myobj&quot;&gt;


&lt;!---- Example of an EJB - The cfobject tag creates the Weblogic Environment
object, which is used to get 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. ---&gt;

&lt;cfobject 
   action = &quot;create&quot;
   type = &quot;java&quot;
   class = &quot;weblogic/jndi/Environment&quot;
   name = &quot;wlEnv&quot;&gt;

&lt;cfset ctx = wlEnv.getInitialContext()&gt;
&lt;cfset ejbHome = ctx.lookup(&quot;statelessSession.TraderHome&quot;)&gt;
&lt;cfset trader = ejbHome.Create()&gt;                
&lt;cfset value = trader.shareValue(20, 55.45)&gt;                   
&lt;cfoutput&gt;
    Share value = #value#
&lt;/cfoutput&gt;
&lt;cfset value = trader.remove()&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="TYPE">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">TYPE</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Optional</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Object type:</p><ul>

<li>com</li>

<li>corba</li>

<li>java</li>
</ul>

<p>(The other object types do not take the type attribute.)</p>

  </td>
  </tr>
  </table>
</div>
<div id="ACTION">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ACTION</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Create: Creates a Java or WebLogic Environment object.</p>

  </td>
  </tr>
  </table>
</div>
<div id="CLASS">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">CLASS</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>Java class.</p>

  </td>
  </tr>
  </table>
</div>
<div id="NAME">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">NAME</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">Required</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>String; name for the instantiated component.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
