|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS Feature Developing a WAP Based E-mail Interface
Developing a WAP Based E-mail Interface
May. 2, 2002 12:00 AM
This article is about developing an application for wireless devices with WAP support. For this I've chosen to implement a WAP-based e-mail client. On the Web, using HTML, this is quickly done with ColdFusion. This should also be true for WAP, I thought. Whether or not it turns out to be true...well, just read on. Okay, it did turn out to be easy, since CFDJ has published several articles about the design and pitfalls of WAP development in the last few months. I strongly suggest that you also take a look at the two-part article "Developing Wireless Apps with ColdFusion" by Charlie Arehart (CFDJ, Vol. 2, issues 8, 9). To start developing a real-world WAP application, you need to know the basics of WAP and WML, such as knowing that a WML "page" is called a "card," and a "deck" is a collection of "cards" being transferred all at once. You'll also need intermediate skills in ColdFusion, especially an understanding of the <CFPOP> and <CFMAIL> tags we're going to use in this application. But if you're a novice, don't be discouraged if these terms mean nothing to you. You'll get to know them all during the course of this article. I recommend that you download and install the mobile phone simulator UP.SDK from www.openwave.com (formerly phone.com) on your PC (see the referenced Arehart article for more details) so you can test this application without a WAP-capable device. Take a look at Figure 1, which diagrams the application's flow. To better understand the diagram, I've provided a number of screenshots (see Figures 2-6). As I explain the flow in the next paragraphs, you can directly link the screenshots to the different states in the UML diagram. As you can see in Figure 1, after providing the login information, the mobile user can either check for mail or compose new mail (see also Figures 2 and 3). When checking for new mail, the CF server uses the provided login information (stored into the session) to access the user's mail account via <CFPOP> and displays the result as a listing of all mail headers (see Figure 4). After selecting a message, the details are shown in a separate card (see Figure 5), where the user can decide either to open the mail or to delete it from the server. After opening an e-mail, the user can read it and then either return to the inbox for more mail, delete it from the server, or send a reply (see Figure 6). When you look at the source code on the Web (at www.sys-con.com/coldfusion/sourcec.cfm), you'll see that I first coded this application in HTML for the Web browser to be sure of its functionality, then modified the HTML prototype into a WAP/WML solution for wireless devices. I originally thought I'd better not do this since some concepts of application flow that work well in HTML would certainly not work in WML and vice versa, but after I finished the prototype, the change to WML was easier than I expected. Naturally, this kind of prototyping only works when you're thinking of WML all the time and concentrating on the flow of your mobile phone application. But with this in mind, you can quickly ensure that your application's features are working, since testing and debugging in an HTML-based Web browser is much easier than with WML on WAP devices (you all know how to debug in the HTML/Web browser environment, but I'm sure not all of you have a good way to track errors using a mobile phone). Once the HTML prototype was completed, I felt a little sad about dropping it after having ported it on WML, so I had the templates check for WAP devices or HTML-capable browsers to decide which version to send to the client. This was done with just a few lines of simple code: <!--- Test of WAP-Devices (Auto-Detect) --->Here we check the CGI variable CGI.HTTP_ACCEPT for the MIME types the client browser accepts. If the client accepts "text/vnd.wap.wml", you can be sure it's a mobile WAP device; if it doesn't, most likely it's the usual HTML-capable Web browser. Having placed this simple check inside the Application.cfm file (see Listing 1), we can tell whether the user is "surfing" with a mobile WAP phone or a standard Web browser. As you'll see when you look at the other code listings, most pages check for this flag at the beginning and serve different content depending on whether it's WML or HTML. For more complex applications that behave differently when accessed via WAP than they do via a conventional Web browser, you might think of writing two sets of templates (at least for presenting the user interface) instead of just checking within each template. For simpler applications, such as the example in this article, the first method - deciding within the templates - is just fine.
Design Considerations for WML
The benefit of designing a card that lists only the mail's subjects, linked to the appropriate card holding the headers (sender, date, etc.) within the same deck, is a more comfortable user interface without any performance loss since all the headers are transferred within the same deck and therefore available locally without any server round-trips. By hiding detailed information on subsequent cards and presenting something akin to an index card on top, you can design a good WML deck. On the other hand, putting too much detail in one deck exceeds the maximum (which is about 2 kilobytes per compiled deck sent from the WAP gateway). This is why I put just the header details in the deck, not the actual mail content, which could be quite a lot of text. After viewing the header details, a user can choose whether to fetch the content or continue browsing other e-mail. On the subject of design considerations, mobile phones of course have no PC keyboard, although I sometimes wish they did - I hate typing in long text using the cumbersome keypad. Okay, this is a bad example, I thought, since e-mail often involves a lot of typing (especially when composing new mail) - but that's really up to the user: a mobile phone can certainly check new mail, and sometimes handle short text. But when using this example I strongly advise you not to ask for the mail account data with every login. Instead, provide your users with a database-based storage of their account data. As most of you (including me when I coded the example app) change the mail account settings during testing, asking the user to type in all settings at the start is okay. I also did this to keep things as simple as possible, and tried to focus on the WAP-related issues, not on storing login data into a database table (which is definitely not new to you).
Session Management on a Mobile Phone
All this is true if you're dealing with the traditional Web and major browsers. But in terms of microbrowsers running on a mobile device that's not directly connected to your Web server (on mine it's connected through a WAP gateway server of the network supplier), things could be different. Fortunately, the WAP design group (www.wapforum.org), which consists of all major players and companies in the WAP world, has thought about this aspect too, and most WAP gateways keep track of cookies on behalf of the mobile devices and send them back to the server on each subsequent request (as normal browsers would). But to be on the safe side, I suggest you append the #SESSION.UrlToken# to each link in WML (you'll see this often throughout the listings). Talking about links, WML is strictly XML; thus you'll have to watch out for all special characters, including the "&" sign we often use when passing parameters through a URL link. To put it simply, what would normally look like http://www. domain.com/page.cfm?param1=value1& param2=value2¶m3=value3 must be written in WML, that is, http://www.do main.com/page.cfm?param1=value1& amp;param2=value2¶m3= value3. To make it easy to keep track of all XML-relevant special characters, you could also use the following line to output the link via the CF4.5 XmlFormat() function: #XmlFormat("http://www.domain.com/Getting Data Back from the WAP Device to the Application Before I start describing the source code, there's one point left to discuss: how to pass input data back from the mobile device to the application. In traditional Web programming this is done through forms, with form fields passing values either as GET or POST requests to the action page (the latter is done more often, I suppose), as well as by using URL parameters appended to the action page's URL as the query string (the part after the "?") that emulates GET requests. In WML you can submit the input values either as a POST request (using <postfield>s) or add them to a URL link (the equivalent of the GET method). As some gateways don't let <postfield>s pass values correctly (note that the simulators handle them correctly when in HTTP direct mode with no WAP gateway involved), I suggest you use the URL "get" variant, at least for now. A more detailed description of this can be found in Part 2 of Arehart's article, referenced earlier. One nice feature of WML when dealing with form fields is that each value entered into a deck is directly available (in all cards within that deck) as a client-side WML variable. <wml>In this snippet from a WML file the second card directly repeats what the user has entered on the first card's input field. So all input data is directly available in client-side WML variables for further use within the deck. We use these variables to attach the form field's input values as URL parameters to a link to the action pages.
Looking at the Code
This application (see Figure 1 for the state diagram) consists of 11 listings that can be downloaded from www.sys-con.com/coldfusion/sourcec.cfm.
<cfsetting showdebugoutput="No">The <cfsetting> tag disables any debug output on the page to make sure your WML doesn't become invalid XML when debug output is sent to it at the end of the request. Next you'll see <cfcontent type="text/vnd. wap.wml" reset="Yes">, which is for setting the MIME type of the page to "WML", telling the client, "Yes, I'm really WML." The same is true with the XML and doctype declaration, which is a must for every WML page. Now let's take a more detailed look at the source files:
application.cfm (Listing 1)
index.cfm (Listing 2)
"initAccount.cfm?CFID=1&CFT0KEN=95042334& initPop3=$initPop3&Finally, after all "&"s have been escaped by XmlFormat(), the link is written into the <go> WML tag for assigning links to actions. That way the file initAccount.cfm gets all settings as URL parameters.
initAccount.cfm (Listing 3)
mainMenu.cfm (Listing 4)
menu.cfm (Listing 5)
checkMail.cfm (Listing 6)
openMail.cfm (Listing 7)
composeMail.cfm (Listing 8)
sendMail.cfm (Listing 9)
deleteMail.cfm (Listing 10)
error.cfm (Listing 11)
Summary
CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||