380
Example: CFML page that uses the Employee class
Save the following text as JEmployee.cfm:
<html>
<body>
<cfobject action=create type=java class=Employee name=emp>
<!-- <cfset void = emp.init()> -->
<cfset emp.firstname="john">
<cfset emp.lastname="doe">
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
</body>
<cfoutput>
</cfoutput>
</html>
When you view the page in your browser, you should get the following output:
Employee name is john doe
Reviewing the code
The following table describes the CFML code and its function:
Code
<cfobject action=create
<!--- <cfset void=emp.init()>
--->
<cfset emp.firstname="john">
<cfset emp.lastname="doe">
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
<cfoutput>
</cfoutput>
Java considerations
Keep the following points in mind when you write a ColdFusion page that uses a Java
class object:
Employee name is
type=java class=Employee
name=emp>
Employee name is
#lastname#
The Java class name is case sensitive. You must make sure that both the Java code
and the CFML code use Employee as the class name.
Chapter 20 Using cfobject to Invoke Component Objects
#firstname# #lastname#
Description
Load an instance of the Employee Java
class named emp.
Do not call a constructor. ColdFusion
invokes the default constructor when it first
uses the class; in this case, when it
processes the next line.
Set the public fields in the emp object to your
values.
Get the field values back from emp object.
Display the retrieved values.
#firstname#
Need help?
Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?