ColdFusion 9.0 Resources |
Embedding Java appletsThe cfapplet tag lets you embed Java applets either on a ColdFusion page or in a cfform tag. To use the cfapplet tag, first register your Java applet using the ColdFusion Administrator Java Applets page (under Extensions). In the ColdFusion Administrator, you define the interface to the applet, encapsulating it so that each invocation of the cfapplet tag is simple. The cfapplet tag within a form offers several advantages over using the HTML applet tag:
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. Registering a Java appletBefore you can use a Java applet in your ColdFusion pages, register the applet in the ColdFusion Administrator.
Using the cfapplet tag to embed an appletAfter 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. Because you registered the applet and you defined each applet parameter with a default value, you can run the applet with a simple form of the cfapplet tag: <cfapplet appletSource="appletname" name="form_variable"> Overriding alignment and positioning valuesTo override any of the values defined in the ColdFusion 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"> Overriding parameter valuesYou can override the values that you assigned to applet parameters in the ColdFusion Administrator by providing new values for any parameter. To override a parameter, you must have already defined the parameter and its default value in the ColdFusion Administrator Applets page. The following example overrides the default values of two parameters, Param1 and Param2: <cfapplet appletSource="myapplet" name="applet1_var" Param1="registered parameter1" Param2="registered parameter2"> Handling form variables from an appletThe cfapplet tag name attribute corresponds to a variable in the action page, Form.appletname, which holds any value that the applet method returns when it is executed in the cfform tag. Not all Java applets return values. For instance, graphical widgets might not return a specific value. For this type of applet, the method field in the ColdFusion Administrator remains empty, but you must still provide a cfappletname attribute. 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. Reference a Java applet return value in your application page
When your page executes the applet, ColdFusion creates a form variable with the name that you specified. If you do not specify a method, ColdFusion does not create a form variable. |