Welcome!

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

Related Topics: ColdFusion

ColdFusion: Article

Five Cool Things I've Done with ColdFusion

Mailing labels, bar codes, credit cards, and graphing

I'm at my best when I'm challenged. In my consulting business I tend to gravitate towards small businesses with delusions of grandeur. I want to be the one to help them realize their vision and turn their delusion into reality. Looking back, this has been an interesting week. I thought I'd share some of the interesting things I've done and how ColdFusion helped make them possible.

Monday: Bar Codes
I've been working over the past year to Web enable an MS Access based scheduling system. One item of the application generates attendance cards with a bar code on it for all users. When a user shows up for a class, that user will scan in, and the information is used to track attendance. The client wanted to be able to generate the attendance cards (with bar codes) from the Web. How do you do that?

First, you have to realize what bar codes are. They are just text, or data of some sort, that looks like a bunch of parallel lines. If you don't know what I mean, just flip over your copy of ColdFusion: The Complete Reference, and you'll find one. (Or you can look at any book or CD). These bar codes are generated using a special font. The client provided me with the font, named "3 of 9 Barcode." A simple Web search will reveal many places where you can get this font. I recommend downloading it straight from the source at www.squaregear.net/fonts/free3of9.shtml.

Now you're probably thinking that since you have the font name, you can just use the HTML font tag like this: <font name="3 of 9 Barcode">My Bar Code</font>

And you don't even have to use ColdFusion, right? Well, you're on the right track, but things aren't that simple. The first mistake is that you need to put an asterisk (*) before and after the text you want to be able to scan as a bar code. Even with that tidbit of information, you still aren't in the clear. For this approach to work, the bar code font must be installed on the client computer.

When you use a font in HTML like that, that font must be installed on the client computer (not the server), or else a default font is used. The resulting bar code won't scan if it's generated using Helvetica or Times New Roman. (You can trust me on that one.) This font is not a standard font installed on most users computers. Expecting it to be isn't a realistic expectation for Web development. Most people don't have uses for Bar Code fonts in their daily activities. Getting the bar code font installed on all relevant clients of your system would bring you back to the old days of client/server technology where you have to walk through a big dark office building with fluorescent lighting and spend months installing things so the requirements change by the time you're finished with the roll out. There must be a better way, right? Yes!

The answer is to use the ColdFusion Report Builder to generate the attendance cards with bar codes. First, install the bar code font on your development machine and on your production (and/or testing) server. Then, create a new report (or open an existing report). Create a field and give it an expression something like this:

"*" & barcodedata & "*"

In the properties dialog, you should see the 3 of 9 Barcode font listed in the Font name list, as shown in Figure 1. Select that font and your field will look like a bar code. Above the font selection, there is another option for "embedded font." Be sure to select true for this option. Normally, you wouldn't want to embed fonts in a PDF because it makes the overall file size larger, but then you have to ensure that the client computer has the font installed, or it will default itself. Since we don't want to make sure that the client computer has the bar code font installed (for reasons discussed earlier), we embedded it here.

To test the bar codes, you have to scan them. I used a CueCat. The CueCat company has a long disastrous history which results in CueCat scanners being an extremely cheap buy on eBay. Perform a Web search for all the gory details; they are beyond the scope of this article.

Tuesday: Mailing Labels
The mid-week point brought another challenge from above. A client wanted to be able to generate mailing labels. Doing this sort of task with HTML is grueling, tedious, and prone to errors. Especially since different browsers can display the same HTML code in different ways. HTML is not designed for print, and forcing what is on screen to line up with what is on your label sheet is going to be the cause some serious headaches. So, what are the options?

I turned once again to my new best friend, the CF Report Builder. The nice man, Dean, at cfreport.org (no last name is known, but I get the impression he works for Adobe) has created a label wizard for the ColdFusion Report Builder. You can download the wizard at www.cfreport.org/index.cfm?mode=entry&entry=38BBAD81-3048-2D03-0A777CDC2FB60D74. You'll need to have at least 7.01 of the Report Builder installed (and I recommend getting the 7.02 update). In my case, I already had the wizard installed. Since I don't remember installing it, it may have been included in the 7.02 update of the Report Builder. Check your install and you may not have to worry about manually downloading and installing the wizard.

You can find out if you have the label wizard installed by selecting File ‡ New. You should see the Label Creation Wizard as an option in the new dialog, as shown in Figure 2. Select the label creator wizard and click next.

You'll see the first step in the Label Creation Wizard, as shown in Figure 3. Select the label template you want to use. Most labels are based on some form of Avery label template (My client asked for 5160). Select that and click next.

Now you have to define the query fields you want to use to display information on your label, as shown in Figure 4. I manually entered them (The query builder button didn't work for me). Click the next button

The final step in the report builder is to define the layout of your label. Double-click the elements in the left window, and they'll be entered in the right window. The right window is an expression window, but you don't have to worry about writing an expression, because when you click the finish button, text (such as commas) will automatically be escaped when creating the finished template. Save your template and you're good to go.

The last step in the Report Builder is just to run the report using the cfreport tag. Your template will look something like this:

<cfquery name="Getusers" datasource="myDSN">
select firstName, LastName, State, City,. Zip
from users
</cfquery>

<cfreport format="PDF" template="LabelReport.cfr" query="Getusers">
</cfreport>

Your query will most likely be different, depending on the information you want to print on a label, but you should be able to apply these concepts to your own development.

Wednesday: Credit Card Swipes
One of my clients runs an e-commerce business, and the site implementation is about as classic as an on-line shopping cart can come. The client is in the process of opening up a retail store, and I spent some time modifying the shopping cart to accommodate retail transactions. The biggest difference between retail transactions and Web-based transactions is that you have a credit card to swipe. Swiped cards get a much better merchant rate than Internet or phone orders received, so that is an added benefit of the retail store vs. the Internet store.

The client provided me with a USB credit card swiper so that I could test the process. As far as the computer is concerned, the swiper is not much different than a keyboard; you just get a bunch of data in one scan instead of having to type it out manually. The scanned data is sent to the active program running on your machine. This can be notepad (which is great for testing) or the active form field on a Web browser. I used the latter to integrate into their Web based shopping cart.

The data contained on a credit card consists of the card number, some bank routing information, the customer's name, and other miscellaneous information. More details on the specifics of the credit card swipe data are at http://money.howstuffworks.com/credit-card1.htm. To process the credit card data you don't need to know the specifics of what it is. The PayFlow Pro Web API has a field for sending swipe data, so it's easy to send it off the transaction and receive information back just as you would a normal Web transaction. I would expect that most payment processors have a similar option.

Thursday: Processing Bar Codes and Credit Card Swipes
Now that the bar codes were generated, the client wanted to be able to process scanned bar codes in the Web browser. The CueCat, like other bar code readers, operates in the same manner that the credit card scanner does. When you swipe a card or scan a bar code, the scanned (or swiped) information goes to the active screen. If you have a Web browser open, it will go to the selected form field. To start the input page, first we'll need the form:

<form action="BarCodeSCanner.cfm" method="post" name="BarCodeScanner" id="BarCodeScanner">
Scanned Info: <input type="text" name="ScannedInfo">
</form>

This is a form that will submit back onto itself. The form has one input field, with no submit button. For attendance purposes in the scheduling system, the scan had to be as painless as possible without any user interaction, so the form is submitted through JavaScript.

How does the browser know we've scanned something? How do we know when to submit? The answer is through the use of a JavaScript timer. The timer is a JavaScript that counts down from some number to 0. When it reaches 0, it checks whether there is data in the ScannedInfo field (or not) and then submits the form if there is.

I used the JavaScript code located at www.mcfedries.com/JavaScript/timer.asp as a base for this. (Much thanks to Paul McFedries' for his assistance). For space reasons, I'll refrain from copying the full script here. There are four variables to take into account:

  • Secs: The secs variable specifies how many clock ticks until the timer reaches 0. This will count down from the initial value to 0.
  • Delay: This is the amount of milliseconds before the timer checks its next status. 1000 milliseconds are equal to one second, so that is the default.
  • TimerID: The timerID is a variable internal to the script. It specifies when the next clock tick will occur.
  • TimerRunning: The timerRunning variable is a Boolean value that tells us whether the timer is running or not. For all intents and purposes, it is internal to the script and you don't need to worry about it.

    There are three functions that make up the timer:

  • InitializeTimer: The initialize timer function sets the secs variable, stops the timer (if currently running), and then starts the timer.
  • StopTheClock: The stop the clock function runs some script to prevent the clock from running.
  • StartTheTimer: The StartTheTimer function is the meat of the execution. It counts down from the clock tick and executes certain code if the count down is done, or moves onto the next clock tick. Of these three functions, it is the StartTheTimer function that needs a more in depth examination.
function StartTheTimer(){
   if (secs==0){
    StopTheClock()
    if (document.BarCodeScanner.ScannedInfo.value != ''){
     document.BarCodeScanner.submit();
     } else {
      InitializeTimer();
     }

    }else {
     secs = secs - 1
     timerRunning = true
      timerID = self.setTimeout("StartTheTimer()", delay)
   }
}

More Stories By Jeffry Houser

Jeffry is a technical entrepreneur with over 10 years of making the web work for you. Lately Jeffry has been cooped up in his cave building the first in a line of easy to use interface components for Flex Developers at www.flextras.com . He has a Computer Science degree from the days before business met the Internet and owns DotComIt, an Adobe Solutions Partner specializing in Rich Internet Applications. Jeffry is an Adobe Community Expert and produces The Flex Show, a podcast that includes expert interviews and screencast tutorials. Jeffry is also co-manager of the Hartford CT Adobe User Group, author of three ColdFusion books and over 30 articles, and has spoken at various events all over the US. In his spare time he is a musician, old school adventure game aficionado, and recording engineer. He also owns a Wii. You can read his blog at www.jeffryhouser.com, check out his podcast at www.theflexshow.com or check out his company at www.dot-com-it.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
The Internet of Things will greatly expand the opportunities for data collection and new business models driven off of that data. In her session at Internet of @ThingsExpo, Esmeralda Swartz, CMO of MetraTech, will discuss how for this to be effective you not only need to have infrastructure and operational models capable of utilizing this new phenomenon, but increasingly service providers will need to convince a skeptical public to participate. Get ready to show them the money! Speaker Bio: Esmeralda Swartz, CMO of MetraTech, has spent 16 years as a marketing, product management, and busin...
Samsung VP Jacopo Lenzi, who headed the company's recent SmartThings acquisition under the auspices of Samsung's Open Innovaction Center (OIC), answered a few questions we had about the deal. This interview was in conjunction with our interview with SmartThings CEO Alex Hawkinson. IoT Journal: SmartThings was developed in an open, standards-agnostic platform, and will now be part of Samsung's Open Innovation Center. Can you elaborate on your commitment to keep the platform open? Jacopo Lenzi: Samsung recognizes that true, accelerated innovation cannot be driven from one source, but requires a...
SYS-CON Events announced today that Red Hat, the world's leading provider of open source solutions, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Red Hat is the world's leading provider of open source software solutions, using a community-powered approach to reliable and high-performing cloud, Linux, middleware, storage and virtualization technologies. Red Hat also offers award-winning support, training, and consulting services. As the connective hub in a global network of enterprises, partners, a...
P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at Internet of @ThingsExpo, Robin Raymond, Chief Architect at Hookflash Inc., will walk through the shifting landscape of traditional telephone a...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
BSQUARE is a global leader of embedded software solutions. We enable smart connected systems at the device level and beyond that millions use every day and provide actionable data solutions for the growing Internet of Things (IoT) market. We empower our world-class customers with our products, services and solutions to achieve innovation and success. For more information, visit www.bsquare.com.
How do APIs and IoT relate? The answer is not as simple as merely adding an API on top of a dumb device, but rather about understanding the architectural patterns for implementing an IoT fabric. There are typically two or three trends: Exposing the device to a management framework Exposing that management framework to a business centric logic • Exposing that business layer and data to end users. This last trend is the IoT stack, which involves a new shift in the separation of what stuff happens, where data lives and where the interface lies. For instance, it’s a mix of architectural style...
From a software development perspective IoT is about programming "things," about connecting them with each other or integrating them with existing applications. In his session at @ThingsExpo, Yakov Fain, co-founder of Farata Systems and SuranceBay, will show you how small IoT-enabled devices from multiple manufacturers can be integrated into the workflow of an enterprise application. This is a practical demo of building a framework and components in HTML/Java/Mobile technologies to serve as a platform that can integrate new devices as they become available on the market.
SYS-CON Events announced today that SOA Software, an API management leader, will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. SOA Software is a leading provider of API Management and SOA Governance products that equip business to deliver APIs and SOA together to drive their company to meet its business strategy quickly and effectively. SOA Software’s technology helps businesses to accelerate their digital channels with APIs, drive partner adoption, monetize their assets, and achieve a...
SYS-CON Events announced today that Utimaco will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Utimaco is a leading manufacturer of hardware based security solutions that provide the root of trust to keep cryptographic keys safe, secure critical digital infrastructures and protect high value data assets. Only Utimaco delivers a general-purpose hardware security module (HSM) as a customizable platform to easily integrate into existing software solutions, embed business logic and build s...
Connected devices are changing the way we go about our everyday life, from wearables to driverless cars, to smart grids and entire industries revolutionizing business opportunities through smart objects, capable of two-way communication. But what happens when objects are given an IP-address, and we rely on that connection, sometimes with our lives? How do we secure those vast data infrastructures and safe-keep the privacy of sensitive information? This session will outline how each and every connected device can uphold a core root of trust via a unique cryptographic signature – a “bir...
Internet of @ThingsExpo Silicon Valley announced on Thursday its first 12 all-star speakers and sessions for its upcoming event, which will take place November 4-6, 2014, at the Santa Clara Convention Center in California. @ThingsExpo, the first and largest IoT event in the world, debuted at the Javits Center in New York City in June 10-12, 2014 with over 6,000 delegates attending the conference. Among the first 12 announced world class speakers, IBM will present two highly popular IoT sessions, which will take place November 4-6, 2014 at the Santa Clara Convention Center in Santa Clara, Calif...
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
WebRTC defines no default signaling protocol, causing fragmentation between WebRTC silos. SIP and XMPP provide possibilities, but come with considerable complexity and are not designed for use in a web environment. In his session at Internet of @ThingsExpo, Matthew Hodgson, technical co-founder of the Matrix.org, will discuss how Matrix is a new non-profit Open Source Project that defines both a new HTTP-based standard for VoIP & IM signaling and provides reference implementations.

SUNNYVALE, Calif., Oct. 20, 2014 /PRNewswire/ -- Spansion Inc. (NYSE: CODE), a global leader in embedded systems, today added 96 new products to the Spansion® FM4 Family of flexible microcontrollers (MCUs). Based on the ARM® Cortex®-M4F core, the new MCUs boast a 200 MHz operating frequency and support a diverse set of on-chip peripherals for enhanced human machine interfaces (HMIs) and machine-to-machine (M2M) communications. The rich set of periphera...

SYS-CON Events announced today that Aria Systems, the recurring revenue expert, has been named "Bronze Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Aria Systems helps leading businesses connect their customers with the products and services they love. Industry leaders like Pitney Bowes, Experian, AAA NCNU, VMware, HootSuite and many others choose Aria to power their recurring revenue business and deliver exceptional experiences to their customers.
The Internet of Things (IoT) is going to require a new way of thinking and of developing software for speed, security and innovation. This requires IT leaders to balance business as usual while anticipating for the next market and technology trends. Cloud provides the right IT asset portfolio to help today’s IT leaders manage the old and prepare for the new. Today the cloud conversation is evolving from private and public to hybrid. This session will provide use cases and insights to reinforce the value of the network in helping organizations to maximize their company’s cloud experience.
The Internet of Things (IoT) is making everything it touches smarter – smart devices, smart cars and smart cities. And lucky us, we’re just beginning to reap the benefits as we work toward a networked society. However, this technology-driven innovation is impacting more than just individuals. The IoT has an environmental impact as well, which brings us to the theme of this month’s #IoTuesday Twitter chat. The ability to remove inefficiencies through connected objects is driving change throughout every sector, including waste management. BigBelly Solar, located just outside of Boston, is trans...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
Predicted by Gartner to add $1.9 trillion to the global economy by 2020, the Internet of Everything (IoE) is based on the idea that devices, systems and services will connect in simple, transparent ways, enabling seamless interactions among devices across brands and sectors. As this vision unfolds, it is clear that no single company can accomplish the level of interoperability required to support the horizontal aspects of the IoE. The AllSeen Alliance, announced in December 2013, was formed with the goal to advance IoE adoption and innovation in the connected home, healthcare, education, aut...