The cfapplet
tag allows you to embed Java applets in a cfform
. To use cfapplet
, you must first register your Java applet using the ColdFusion Administrator Java Applets page (under Extensions on the Server tab). In the Administrator, you define the interface to the applet, encapsulating it so that each invocation of the cfapplet
tag is very simple.
The cfapplet
tag offers several advantages over using the HTML applet
tag:
cfapplet
requires a form field name
attribute, you can avoid coding additional JavaScript to capture the applet's return values. You can reference return values like any other ColdFusion form variable: Form.
variablename.
cfapplet
tag in your pages only needs to reference the applet name and specify a form variable name.cfapplet.
When an applet is registered, you enter just the applet source and the form variable name:
<cfapplet appletsource="Calculator" name="calc_value">
By contrast, with the HTML applet
tag, you must declare all the applet's parameters every time you want to use it in a ColdFusion page.
Before you can use a Java applet in your ColdFusion pages, you must register the applet in the Administrator.
The following table explains the applet registration fields:
After you register an applet, you can use the cfapplet
tag to place the applet in a ColdFusion page. The cfapplet
tag has two required attributes: appletsource
and name
. Since you registered the applet, and you defined each applet parameter with a default value, you can invoke the applet with a very simple form of the cfapplet
tag:
<cfapplet appletSource="appletname" name="form_variable">
To override any of the values defined in the Administrator for the applet, you can use the optional cfapplet
parameters to specify custom values. For example, the following cfapplet
tag specifies custom spacing and alignment values:
<cfapplet appletSource="myapplet" name="applet1_var" height=400 width=200 vspace=125 hspace=125 align="left">
You can also override the values that you assigned to applet parameters in the Administrator by providing new values for any parameter. In order to override a parameter, you must have already defined the parameter and a default value for it in the ColdFusion Administrator Applets page.
<cfapplet appletSource="myapplet" name="applet1_var" Param1="registered parameter1" Param2="registered parameter2">
The cfapplet
tag requires you to specify a form variable name for the applet. This variable, referenced like other ColdFusion form variables, Form.
variable_name holds the value the applet method returns when it is executed in the cfform
.
Not all Java applets return values. For instance, many graphical widgets do not return a specific value; they do their flipping, spinning, fading, exploding, and that is all. For this kind of applet, the method field in the Administrator remains empty. Other applets, however, do have a method that returns a value. You can only use one method for each applet that you register. If an applet includes more than one method that you want to access, you can register the applet with a unique name for each additional method you want to use.
name
attribute of the cfapplet
tag when you code your cfform
.When your page executes the applet, a form variable is created with the name that you specified. If you do not specify a method, no form variable is created.