Adobe COLDFUSION 9 Manual page 1144

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Code
<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
The following points are important when you write a ColdFusion page that uses a Java class object:
• The Java class name is case sensitive. 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 runs 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 #firstname# #lastname#<br>
Employee salary #DollarFormat(Salary)#<br>
Employee Job Grade #grade#
</cfoutput>
</body>
</html>
In this example, the constructor takes four arguments: the first two are strings, the third is a float, and the fourth is an
integer.
Java and ColdFusion data type conversions
ColdFusion does not use explicit types for variables, while Java is strongly typed. However, ColdFusion data does use
underlying Java types to represent data.
Description
Sets the public fields in the emp object to your values.
Gets the field values back from emp object.
Displays the retrieved values.
Last updated 8/5/2010
1139

Advertisement

Table of Contents
loading

Table of Contents