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
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
SYS-CON Events announced today that Cedexis 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. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
SYS-CON Events announced today that Google Cloud has been named “Keynote 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. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
SYS-CON Events announced today that Opsani 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. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.
SYS-CON Events announced today that Nirmata 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. Nirmata provides a comprehensive platform, for deploying, operating, and optimizing containerized applications across clouds, powered by Kubernetes. Nirmata empowers enterprise DevOps teams by fully automating the complex operations and management of application containers and its underlying ...
SYS-CON Events announced today that Opsani to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. Opsani is creating the next generation of automated continuous deployment tools designed specifically for containers. How is continuous deployment different from continuous integration and continuous delivery? CI/CD tools provide build and test. Continuous Deployment is the means by which...