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
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, 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. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that DXWorldExpo has been named “Global 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. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, 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. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
SYS-CON Events announced today that DXWorldExpo has been named “Global 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. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, discussed the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insights from the vast t...
SYS-CON Events announced today that EnterpriseTech has been named “Media 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. EnterpriseTech is a professional resource for news and intelligence covering the migration of high-end technologies into the enterprise and business-IT industry, with a special focus on high-tech solutions in new product development, workload management, increased effic...
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 Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, 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. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and ...
SYS-CON Events announced today that CHEETAH Training & Innovation 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. CHEETAH Training & Innovation is a cloud consulting and IT training firm specializing in improving clients cloud strategies and infrastructures for medium to large companies.
SYS-CON Events announced today that Datanami has been named “Media 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. Datanami is a communication channel dedicated to providing insight, analysis and up-to-the-minute information about emerging trends and solutions in Big Data. The publication sheds light on all cutting-edge technologies including networking, storage and applications, and thei...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...