MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 750

Developing coldfusion mx applications
Table of Contents

Advertisement

Reviewing the code
The following table describes the CFML code and its function:
Code
<cfobject action=create
type=java class=Employee
name=emp>
<!--- <cfset emp.init()> --->
<cfset emp.firstname="john">
<cfset emp.lastname="doe">
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
<cfoutput>
Employee name is #firstname#
#lastname#
</cfoutput>
Java considerations
Keep the following points in mind when you write a ColdFusion page that uses a Java class object:
The Java class name is case-sensitive. You must ensure that the Java code and the CFML code
use Employee as the class name.
Although Java method and field names are case-sensitive, ColdFusion variables are not case-
sensitive, and ColdFusion does any necessary case conversions. As a result, the sample code
works even though the CFML uses emp.firstname and emp.lastname; the Java source code uses
FirstName and LastName for these fields.
If you do not call the constructor (or, as in this example, comment it out), ColdFusion
automatically invokes the default constructor when it first uses the class.
Using an alternate constructor
The following ColdFusion page explicitly calls one of the alternate constructors for the Employee
object:
<html>
<body>
<cfobject action="create" type="java" class="Employee" name="emp">
<cfset emp.init("John", "Doe", 100000.00, 10 )>
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
<cfset salary=emp.GetSalary()>
<cfset grade=emp.GetJobGrade()>
<cfoutput>
Employee name is
Employee salary #DollarFormat(Salary)#<br>
Employee Job Grade
</cfoutput>
</body>
</html>
750
Chapter 33: Integrating J2EE and Java Elements in CFML Applications
Description
Loads the Employee Java class and gives it an object name of
emp.
Does not call a constructor. ColdFusion invokes the default
constructor when it first uses the class; in this case, when it
processes the next line.
Sets the public fields in the emp object to your values.
Gets the field values back from emp object.
Displays the retrieved values.
#firstname# #lastname#<br>
#grade#

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents