Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

A Cold Cup O'Joe Part 8 of 8

A Cold Cup O'Joe Part 8 of 8

Java applets are a much-maligned technology in the Internet world. Originally a major focus of the Java platform, they've retreated from their former place in the spotlight.

Problems with browsers, corporate conflicts, and being outflanked by faster and (arguably) lighter-weight tools like Macromedia's Flash have diminished the popularity of applets considerably. Despite this, they continue to be used for a variety of purposes. What's more, they're often the only solution since most other technologies have focused on limited platforms while Java purports to be usable everywhere.

Overview
For several versions of ColdFusion, applets have enhanced the client side of a number of ColdFusion applications. While CFML has a tag, CFAPPLET, for integrating with applets, some applets have actually prompted the creation of specialized tags just for their functionality. Tags like CFGRID and CFTREE have been in the vocabulary of ColdFusion developers for some years now.

Like Java servlets, and unlike the other Java technologies discussed in this series, no special configuration needs to be made in the Java Settings page for these to work. Everything happens in the browser. The only time the ColdFusion Administrator is needed is to register an applet for use with the CFAPPLET tag.

Setup
In this article all examples assume that the accompanying files are installed in a directory called "banners" off the local Web server's root directory.

The Applet
This article shows a number of different ways to integrate Java applets in a ColdFusion application. To stay within the scope of the article, I'll use a simple but useful banner applet to display a single clickable image or rotate through a set of clickable images.

For convenience, the applet, ClickBanner, is contained in a single Java source (producing two class files because of an inner class). The class runs an additional thread if more than one banner item is specified. ClickBanner takes a number of parameters, as seen in Table 1.

Applets in HTML
There are two tags in HTML for handling Java applets: the deprecated APPLET tag and the newer OBJECT tag. Despite being deprecated, the APPLET tag is still broadly used. In fact, both Sun's latest applet examples and ColdFusion's own CFAPPLET tag (discussed later) use it.

APPLET Tag
The original embedded-content tag, APPLET is pretty simple to use, as can be seen in the snippet below (from Listing 1, AppletExample1.html):

<applet code="ClickBanner.class"
codebase="http://localhost/banners/" width="468" height="60">
<param name="item0"
value="http://localhost/banners/megatokyo.gif
|http://www.megatokyo.com">
</applet>

There are actually a broader number of attributes for this tag, as shown in Table 2. (This list doesn't include the attributes added to all HTML elements in 4.x for consistency, such as style, alt.)

OBJECT Tag
One problem with using the OBJECT tag is that it necessitates use of the Java plug-in. Although a discussion on the use of the OBJECT tag with Java applets is beyond the scope of this article, extensive documentation is available at http://java.sun.com/products/plugin/. There are even tools for automatically migrating your APPLET tag directives to OBJECT tag directives.

Listing 2 is an HTML document, AppletExample2. html, that contains an example, but it works only if the Java plug-in is installed.

Applets in ColdFusion
Using ColdFusion's applet interface, CFAPPLET, is an excellent way to work with applets that have a fixed set of parameters. There are a couple of prerequisites:

  • Applets must be registered in the ColdFusion Administrator.
  • CFAPPLET must be used subordinate to CFFORM.
CF Administrator's Java Applets Page
Using an applet with the CFAPPLET tag requires that it first be registered through the ColdFusion Administrator. The main Java applets page (see Figure 1) can be seen on the Administrator's default server menu display under the Extensions heading (Server > Extensions > Java Applets).

Depending on your configuration (and whether you're using ColdFusion 4.5x or 5.x), you may see other applets already registered. The most common one is the COPYTEXT applet entry (used with ColdFusion's own applet-backed tags). It's here that you register the ClickBanner applet:

  1. Click the "Register New Applet" button.
  2. Complete the Add/Registered Applet page (shown in Figure 2) and submit the form with the values in Table 3.
CFAPPLET
The CFML wrapper on the APPLET tag, CFAPPLET, requires preparation in the CF Administrator and must be placed subordinate to a CFFORM tag. Aside from those basic requirements, using the CFAPPLET tag has only two required attributes (the complete list appears in Table 4): appletSource, the name of the registered applet; and name, the identifier given to the applet instance. This is mostly because so many defaults can be gotten from the registered data supplied to the Administrator.

Since the majority of the settings are looked up in the CF server registry, calling a registered applet with CFAPPLET is short work, as exemplified in this snippet from AppletExample3.cfm (see Listing 3):

<cfform action="http://localhost/banners/AppletExample3.cfm" method="POST">
<cfapplet name="banner" appletsource="banner"
item0="http://localhost/banners/megatokyo.gif
|http://www.megatokyo.com">
</cfform>

These few lines give us everything we've come to expect from the previous examples.

Applet-Backed Custom Tag
The two approaches looked at so far place the developer fairly close to the applet itself. HTML's APPLET tag and and CFML's CFAPPLET tag require you to know a thing or two about the applet being used. This is where wrapping the applet in a custom tag can be very powerful. (This was actually done early on for CFML additions with CFGRID, CFTREE, and the like. These UI-oriented tags are really just thin wrapping over some pretty robust Java applets.) Doing so provides a number of important benefits: defaulting content, derived and housekeeping attributes, and applet lifecycle shielding.

Defaulting Content
While CFAPPLET allows for this through the applet registry, it doesn't allow you to script the logic. Using a custom tag allows a reactive default to be set where conditions can be checked.

Derived and Housekeeping Attributes
Certain things that can foul up a page through a minor typo can often be avoided this way. Specifically, in the case of the ClickBanner applet, where a count parameter is set to tell the applet how many image/link banner combinations to pick up, this is a very useful feature. The ClickBanner custom tag counts these and generates the count parameter itself.

Applet Lifecycle Shielding
Once an interface has been established via a custom tag, minor changes to the applet can be hidden. Applet parameter name changes, changes to default values, even new required parameters can often be masked by a custom tag.

ClickBanner Custom Tag
Following in the footsteps of ColdFusion's own designers, I've created a custom tag to wrap the ClickBanner applet. This custom tag is really a set with one subordinate to the other. CF_CLICKBANNER is the parent tag and sets up the applet; CF_BANNERITEM is the subordinate tag identifying the individual banner images and links. It won't take long to see that these two tags simplify the coding. CF_CLICKBANNER has only two required attributes (see Table 5 for the complete list), as does CF_BANNERITEM (see Table 6).

A simple example of this tag set can be seen in the following snippet (from Listing 4, AppletExample4. cfm):

<cf_clickbanner width="468" height="60">
<cf_banneritem image="http://localhost/banners/megatokyo.gif"
destination="http://www.megatokyo.com">
</cf_clickbanner>
Wrapping It Up
Despite the maligning and declining popularity, Java applets still have numerous uses. They can be very useful when concerns about the target platform would make alternate solutions difficult to implement. While some tools are becoming more technologically competitive, their penetration is not nearly as great (Java applets run everywhere Flash does, but Flash doesn't run everywhere an applet does).

Given the variety of different implementations available in CFML for incorporating an applet, they can in many cases be considered a slam-dunk option. Like any technology, when used judiciously it can be a great benefit.

More Stories By Guy Rish

Guy Rish is a ColdFusion and .NET developer at Vente as well as President at Gestaltech. He is an active developer and writer for various languages and technologies, and has contributed work in books on ColdFusion MX, Flash MX, and Dreamweaver MX. He blogs at ccoj.coldfusionjournal.com.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Elon Musk is among the notable industry figures who worries about the power of AI to destroy rather than help society. Mark Zuckerberg, on the other hand, embraces all that is going on. AI is most powerful when deployed across the vast networks being built for Internets of Things in the manufacturing, transportation and logistics, retail, healthcare, government and other sectors. Is AI transforming IoT for the good or the bad? Do we need to worry about its potential destructive power? Or will we...
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
While some developers care passionately about how data centers and clouds are architected, for most, it is only the end result that matters. To the majority of companies, technology exists to solve a business problem, and only delivers value when it is solving that problem. 2017 brings the mainstream adoption of containers for production workloads. In his session at 21st Cloud Expo, Ben McCormack, VP of Operations at Evernote, will discuss how data centers of the future will be managed, how th...
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...
SYS-CON Events announced today that Enroute Lab will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enroute Lab is an industrial design, research and development company of unmanned robotic vehicle system. For more information, please visit http://elab.co.jp/.
Agile has finally jumped the technology shark, expanding outside the software world. Enterprises are now increasingly adopting Agile practices across their organizations in order to successfully navigate the disruptive waters that threaten to drown them. In our quest for establishing change as a core competency in our organizations, this business-centric notion of Agile is an essential component of Agile Digital Transformation. In the years since the publication of the Agile Manifesto, the conn...
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...