ColdFusion and WAP
ColdFusion is a powerful web application development environment from Allaire. Designed originally to create HTML applications for web browsers, it can just as easily be used to create WML applications for wireless devices.
ColdFusion is exceptionally well suited to wireless application development. It's easy to use—and just as important—it's easy to understand someone else's code that you have to support. It's scalable, works in multiple environments, and is widely supported.
If you're looking to take your WAP applications to the next stage, including dynamically generated, database-driven output, as well as data entry applications, scheduled content (reminders and notifications), and more, ColdFusion is a great place to start.
Topics covered in this chapter include:
q A brief introduction to ColdFusion and it's features
q Key issues when developing WAP applications with ColdFusion
q ColdFusion Studio/HomeSite features useful for WAP development
q Techniques, tricks and traps
If you're an experienced ColdFusion coder, you'll most likely want to skip the next section, and move straight onto WAP and ColdFusion, but whether you're new to ColdFusion or experienced, this chapter will give you the jump-start you need to begin creating wireless applications in ColdFusion.
ColdFusion (CF) is the leading cross-platform web application server. It can be used on Windows as well as UNIX platforms, and it works with nearly all web servers and databases. CF's core strength has been its ability to make it easy to integrate databases with web applications. By web applications, we mean web sites that are driven by programs that generate web pages. These pages are often generated from database data, though web applications are also the key to creating interactive, two-way web pages, such as forms, search interfaces, data entry applications, and more.
While ColdFusion was designed to generate web pages that send HTML to web browsers, it can just as easily be used to generate WML pages sent to microbrowsers. This chapter describes how to do that, and it describes how ColdFusion programming works, for those new to it. There are some introductory facets that should be discussed first.
ColdFusion works in tandem with your web server to serve web pages to your site visitors. ColdFusion is not a web page design tool, like Microsoft FrontPage, Macromedia DreamWeaver, or NetObjects Fusion. It's more akin to Active Server Pages. In fact, CF and ASP can do pretty much the same things.
ColdFusion's programming language, CFML, is tag-oriented and can be learned very easily whereas ASP is script-oriented and typically leverages Visual Basic programming skills. (Another benefit of ColdFusion over something like ASP is that a ColdFusion program written for a Windows server can run virtually unchanged on a UNIX or Linux box.)
Whereas tools like FrontPage and DreamWeaver help you design and layout static web pages that you then place on the server for the user to see, with web application servers like ColdFusion and ASP you instead place a program on the web server. When a visitor enters a web address (URL) for that program, the program is executed on the server. The following picture depicts the process of how ColdFusion processing works:
|
In the case of ColdFusion, the web server receives the request to execute the page and tasks the ColdFusion server, generally running on the same box, to run the program. The program (often referred to generically in CF as a "template") creates HTML or WML as a result, which is sent back to the end user by way of the web server.
Keep in mind that the ColdFusion tags will NOT be sent to the browser or microbrowser. The browsers understand only HTML or WML elements. ColdFusion templates are evaluated by the ColdFusion Server software, and any resulting HTML or WML code is sent to the browser with the ColdFusion tags stripped and their result displayed instead.
The end user needs nothing but a normal browser. When they request a page from a ColdFusion server (whether from a web or WAP browser), the result they see is just a web or WAP page like any other that they would browse. They have no clear indication that the page has been served by ColdFusion. The result of executing a ColdFusion page is just HTML or WML (whichever the ColdFusion page was designed to create), though that code can be generated from a database, can show the result of a search, and more, as described previously.
As for ColdFusion code itself, CFML is very straightforward. The following is a classic Hello World example as would be used for an HTML web page:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>Hello World</h2>
<CFSET location="World">
<CFOUTPUT>
Hello #location#.
</CFOUTPUT>
</body>
</html>
This is a trivial example, but it demonstrates two key points. ColdFusion is a programming language, and as such it supports creating and processing variables. Here we have created a location variable using the ColdFusion tag CFSET, assigning it the value "World". Then we have displayed the result of that variable to the user by way of the ColdFusion tag CFOUTPUT. Obviously, there's much more that ColdFusion can do. There are more substantial examples offered in the remainder of this chapter and in the example source code available for this chapter.
CFML supports more than 70 server-side tags, 200 functions, and 800 third-party components – making it the most productive environment available for creating advanced Web applications.
ColdFusion offers capabilities that can extend your wireless applications to much broader horizons, including the ability to query and update virtually any database (including SQL Server, Sybase, Oracle, Access, and many more), integration with other objects on your server (including COM, CORBA, and Java, to name a few), portability among multiple operating systems and web servers (on both UNIX and Windows), and support for state management, error handling, load balancing, failover, and much more. See the Allaire web site for more information on ColdFusion (http://www.allaire.com/Products/coldfusion/).
We explained that ColdFusion is a server application, as compared to tools like FrontPage and DreamWeaver, which are web page design and editing tools. The ColdFusion programs (or templates) that you create are simple text files that include tags that describe how the program is to be executed. While you can use a tool like DreamWeaver or NetObjects Fusion (but not FrontPage) to create ColdFusion templates, it's generally more suitable to create them in a text editor.
Allaire has created a powerful text editor that not only makes it easy to create HTML (and now WML) pages but also adds various features to make it easy to create ColdFusion pages. ColdFusion Studio is that editor. It's actually based on another Allaire HTML editor, called HomeSite. This award-winning editor is highly regarded for its ease of use and powerful web page editing features. In fact, it's included with DreamWeaver and NetObjects Fusion as the text editor of choice for those web page design tools.
You can use either Studio or HomeSite, both available for purchase at Allaire's site, to develop ColdFusion programs generating either HTML or WML, but Studio has a few more features (database tools, remote development tools, and an interactive debugger for HTML page testing) than HomeSite.
Another benefit of ColdFusion Studio is that it includes a single-user version of ColdFusion Server. This is great for developers who test their programs, locally but ultimately place them on a remote server.
It's important to remember the difference between ColdFusion Studio (the editor used by developers to create CF templates) and ColdFusion Server (the web application server that works in tandem with a web server to serve web pages to visitors).
Later in this chapter, we'll explain how Studio and its cousin HomeSite have been modified in their latest versions to support WML tags.
It's not necessary to download and install ColdFusion server to benefit from the information provided in this chapter, but to run the examples you will need to have access to a server running ColdFusion.
ColdFusion Server, as well as the web page editors ColdFusion Studio and HomeSite, can be purchased from Allaire at http://www.allaire.com.
ColdFusion Server is available in three versions. The first, ColdFusion Express is a free, limited functionality version of ColdFusion. Designed to give web developers an easy entry into ColdFusion programming, it unfortunately cannot currently be used to serve WML pages (see the discussion later in this chapter).
ColdFusion Professional is the minimum configuration needed to serve WML sites. ColdFusion Enterprise, the third configuration, adds technology specifically suited to large-volume, transaction-intensive web applications such as load balancing, failover, native database drivers, CORBA support, and more. Thirty-day evaluation versions of each product are available for download at the Allaire site.
To serve your own ColdFusion programs, it is not necessary to purchase and install ColdFusion Server. There are hundreds of commercial web hosting providers, advertised in nearly every PC and web developer-oriented magazine. Many, if not most of them, offer ColdFusion as one of their services. In that case, you develop your applications on your local workstation and then send them (generally via FTP) to the remote server to be accessed by your visitors.
Unfortunately, we really don't have the space in this chapter to explain setting up ColdFusion. The excellent ColdFusion manuals provide ample explanation and the best recommendation is to read those carefully if you want to run ColdFusion before proceeding with this chapter.
Keep in mind as well that the intent is to make your ColdFusion pages available to external WAP visitors. Unless you have a full-time Internet connection on your workstation, it really doesn't make sense to install ColdFusion Server there (except for testing or development purposes).
You should install ColdFusion on a machine intended to be used as a dedicated web server. Then you can either do your development directly on that server, or perhaps more appropriate, develop your ColdFusion templates on a local workstation (running the single-user version that comes with ColdFusion Studio) and then move them to the production server.
Remember, as we mentioned previously, that ColdFusion works in tandem with web server software. You will first need a web server installed and running before installing ColdFusion. There are several free ones, for both Windows and UNIX platforms.
Configuration of the web server for WML development has been discussed in previous chapters, where you learned to associate MIME types with specific file extensions, such as .wml and .wmls.
ColdFusion pages (or, again, programs or templates as they may be referred to) always have an extension of .cfm (or, less often, .cfml). As such, there is no specific WAP configuration to be done for the web server to support ColdFusion pages that create WML output.