
1138
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Las
t
upda
te
d 8/5/2010
JobGrade = grade;
}
public void SetJobGrade(String Grade) {
if (Grade.equals("CEO")) {
JobGrade = 3;
}
else if (Grade.equals("MANAGER")) {
JobGrade = 2;
}
else if (Grade.equals("DEVELOPER")) {
JobGrade = 1;
}
}
public int GetJobGrade() {
return JobGrade;
}
}
A 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 emp.init()> --->
<cfset emp.firstname="john">
<cfset emp.lastname="doe">
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
</body>
<cfoutput>
Employee name is #firstname# #lastname#
</cfoutput>
</html>
When you view the page in your browser, you get the following output:
Employee name is john doe
Reviewing the code
The following table describes the CFML code and its function:
Code
Description
<cfobject action=create type=java
class=Employee name=emp>
Loads the Employee Java class and gives it an object name of emp.
<!--- <cfset emp.init()> --->
Does not call a constructor. ColdFusion calls the default constructor when it first uses
the class; in this case, when it processes the next line.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...