ColdFusion application servers can use either the COM Corda Embedder (Windows) or the Java Corda Embedder (other platforms). In both cases, the code looks almost exactly alike, and is very similar to the code you created for the JavaScript embedder in Chapter 2.
Embedding a PopChart+OptiMap image into a ColdFusion page can be broken down into the following steps:
Example 3.8 and Example 3.9 at the end of this section show you how the web page from Example 2.8 would look as a ColdFusion Page.
Note: This documentation assumes that if you want to embed a PopChart+OptiMap image in a ColdFusion Page, you already know how to use ColdFusion. If this is not the case, you may wish to brush up on ColdFusion before continuing.
Installing the Library
The instructions for installing the Corda Embedder differ according to which version you use.
COM Corda Embedder (Windows)
If you are using ColdFusion MX on Windows, be sure you have updated your server to the latest version using the ColdFusion MX Updater Release 1. This is available at http://www.macromedia.com/support/coldfusion/releasenotes/mx/releasenotes_mx_updater.html. You will need to apply this update to fix a bug in ColdFusion MX that prevents it from accessing Window's Component Object Model (COM).
Other than that, you don't need to do anything. The COM version of the Corda Embedder is installed automatically for you.
Java Corda Embedder (other platforms)
You will need to put the CordaEmbedder.jar file, located in the dev_tools/embedder/java folder, in the classpath of a Java Application Server. If you do not know how to add a Jar file to your ColdFusion's classpath, refer to "Java Corda Embedder (other platforms)" of the PopChart+OptiMap Installation and Administration Guide.
Instantiating a Corda Embedder Object
To instantiate a Corda Embedder object on ColdFusion, you should use the <cfobject> tag. You should set the name attribute of this tag to the name of your Corda Embedder object (e.g. myImage) and the action attribute to Create.
The values of the other attributes of this tag will depend upon the version of Corda Embedder that you use.
Com Corda Embedder (Windows)
Set the type attribute to COM and the class attribute to Corda.Embedder.
<cfobject type="COM" action="Create" name="myImage" Class="Corda.Embedder">
Java Corda Embedder (Other Platforms)
Set the type attribute to Java and the class attribute to com.corda.CordaEmbedder.
<cfobject type="Java" action="Create" name="myImage" class="com.corda.CordaEmbedder">
Note: You do not need to close the cfobject tag (i.e. do not use a </cfobject> tag).
Delimiting the Code For Your PopChart+OptiMap Image
Except for instantiating the Corda Embedder object and writing the embedding HTML to the web page, all Corda Embedder code should go inside of a <cfscript> tag, as in the following code segment:
<cfscript>
myImage.appearanceFile = "apfiles/line.pcxml";
myImage.loadPCXML("http://myserver.com/?graph1");
</cfscript>
Syntax Notes
Although almost all of the code looks the same in ColdFusion for the Java and COM versions of Corda Embedder, remember that code that uses the Java Corda Embedder will act like Java code, while code that uses the COM Corda Embedder will act like COM code.
This means that if you use Corda Embedder methods that act differently in the Java and COM versions (e.g. setDBQuery()), you need to be sure to use the correct syntax. If you add additional code, be sure that it conforms to the syntax of the language you have chosen. Also, please consult "ASP Syntax Differences" for additional information about using the COM Corda Embedder.
Setting the Server Information
As mentioned in "Server Addresses", server-side versions of Corda Embedder require you to tell them the location of your PopChart+OptiMap server.
You need to set two values: the address that the web client will use to access your PopChart+OptiMap server (externalServerAddress), and the address that the Corda Embedder will use to access your PopChart+OptiMap server (internalCommPortAddress).
For example, if the Corda Embedder communicates with your PopChart+OptiMap server at 10.0.1.1:2002, and your web clients request images from http://myserver.mycompany.com:2001, you need to include the following lines in the code that generates your PopChart+OptiMap image:
myImage.externalServerAddress = "http://myserver.mycompany.com:2002";
myImage.internalCommPortAddress = "10.0.1.1:2002";
Your PopChart+OptiMap administrator should be able to tell you what values you need to use for these settings. If you are having trouble figuring these values out, see "Server Addresses".
Note: If you are using the PopChart+OptiMap servlet instead of the PopChart+OptiMap server, you must also set the isPostRequest attribute to true.
Specifying Image Information
After you have specified your server address information, you will need to give Corda Embedder some information about the PopChart+OptiMap image you wish to embed.
There are numerous Corda Embedder commands you can use to specify image information. Fortunately, these commands are consistent in all web application environments (with the exception of several syntax differences, as previously explained in "Syntax Notes"). Thus, it is unnecessary to discuss each of these commands individually at this time.
Important: When using ColdFusion MX with the COM Corda Embedder, setting the height and width attributes will cause an error. This is because of a bug in ColdFusion MX that does not allow the passing of integers to a COM object. Until this bug is fixed, we have added two string attributes in the COM Object that you should use instead. They are called height4MX and width4MX.
myImage.height4MX = "350";
The table below indicates where you can learn how to specify various types of information for your PopChart+OptiMap image. You will always need to specify an appearance file and the image size. Any other information is optional.
|
Topic
|
Where To Go
|
|---|---|
![]() |
|
|
Annotations
|
|
|
Appearance File
|
|
|
Content Delivery / Presentation Control
|
|
|
Data
|
|
|
Drill-down
|
|
|
Graph or Map Customization
|
|
|
Image Size & Format
|
|
Writing the Image to Your Web Page
When you are ready to actually write your embedding HTML to the ColdFusion page, you will need to output the getEmbeddingHTML() method. To do this, use the <cfoutput> tag, as shown below. Be sure to put pound signs before and after the myImage.getEmbeddingHTML() statement.
<cfoutput>#myImage.getEmbeddingHTML()#</cfoutput>
Complete Example Code
The following ColdFusion page will use the Java Corda Embedder to produce exactly the same results as the page you created in Chapter 2.
COM
Example 3.8 Embedding a PopChart+OptiMap Image with ColdFusion (COM)
<html>
<head>
<title>My First Embedded Image</title>
</head>
<body>
<h1>This is your image</h1>
<hr>
<!-- insert embedder code here -->
<cfobject type="COM" action="create" name="Chart" Class="Corda.Embedder">
<cfscript>
myImage.externalServerAddress="localhost:2001";
myImage.internalCommPortAddress = "localhost:2002";
myImage.appearanceFile = "examples/apfiles/bar.pcxml";
myImage.width = 600;
myImage.height = 400;
myImage.pcScript = "title.setText(Hello World)";
</cfscript>
<cfoutput>
#myImage.getEmbeddingHTML()#
</cfoutput>
<hr>
<p>If you see an image above, congratulations. You have successfully embedded your first image.</p>
</body>
</html>
Java
This last ColdFusion Page uses the Java Corda Embedder to produce the same results.
Example 3.9 Embedding a PopChart+OptiMap Image with ColdFusion (Java)
<html>
<head>
<title>My First Embedded Image</title>
</head>
<body>
<h1>This is your image</h1>
<hr>
<!-- insert embedder code here -->
<cfobject TYPE="Java" ACTION="Create" CLASS="com.corda.CordaEmbedder" NAME="myImage">
<cfscript>
myImage.externalServerAddress="localhost:2001";
myImage.internalCommPortAddress = "localhost:2002";
myImage.appearanceFile = "examples/apfiles/bar.pcxml";
myImage.width = 600;
myImage.height = 400;
myImage.pcScript = "title.setText(Hello World)";
</cfscript>
<cfoutput>
#myImage.getEmbeddingHTML()#
</cfoutput>
<hr>
<p>If you see an image above, congratulations. You have successfully embedded your first image.</p>
</body>
</html>

CORDA