Originally Published: Tuesday, 28 August 2001 Author: S.D. Campbell
Published to: develop_articles/Development Articles Page: 2/3 - [Printable]

WAP and the Wireless Web: Part 2

Sean Campbell continues his series on the wireless web and Linux with part 2 of his look at WAP. In this installment we take a closer look at WML, the language used on your server to define a document for a wireless device.

Select Lists, Variables and Tasks  << Page 2 of 3  >>

Select Lists, Variables and Tasks

Select lists are something that every web designer should recognize. On the web they are used quite extensively to create drop-down lists for forms and navigation bars. Their use in WAP is similar, but unlike HTML, where a properly coded select list must appear inside a form, in WML select lists can appear on their own. In the world of the wireless web, using a drop-down list to select a link is both efficient and practical.

Every select list consists of two elements; the <select> element which defines the list as a whole, and the <option> elements within <select>, each of which define a single option. A menu list could be created simply by coding the following select list:

Select a Section: 
<select name="menu" value="enhance">
	<option value="home">Home</option>
	<option value="learn">Learn</option>
	<option value="enhance">Enhance</option>
	<option value="develop">Develop</option>
	<option value="interact">Interact</option>
	<option value="opinion">Opinion</option>

The name attribute for <select> is the name of the variable that the value attribute of the <option> selected by the user will be stored in. The value attribute for <select> sets the default value should the user not select any <option>.

As mentioned above, values from select lists are stored inside a variable defined by the <select> tag's name. Variables are something new to WML which HTML and XHTML do not have but they should look very similar to anyone who has worked with Perl's scalars. Variables in WML can be accessed (or expanded) by prefacing the name of the variable with a dollar sign ($). To access the value of the select list above, we would write the variable name as $menu. Variables are often used to generate dynamic URLs or query strings for URLs based on user input. For this reason we have the ability to encode special characters in a variable for use in URLs by calling the variable in this manner: $(menu:e), where e stands for the type of encoding required. The conversion types are escape or e to escape a sequence, unesc or u to unescape a sequence, and noesc or n to ensure no conversion is done.

Variables are a very useful part of the WML language, but can be troublesome at times when you aren't expecting variable expansion to take place. To ensure that a variable is not expanded, prefix the variable name (with dollar sign) with another dollar sign. So while $menu will be expanded $$menu will not be.


The final part of our introduction to WML will cover tasks. Tasks are another part of the language, which has no real parallel in HTML or XHTML, but are very useful when working on the wireless web. A task can simply be seen as a command to be executed by the micro-browser. A simple hyperlink, already covered with the <a> element, can also be created by using the <go> task:

<do type="accept"> <go href="#Card2" /> </do>

Not necessarily efficient, but effective nonetheless. Tasks are more useful when sending data to another deck, or going to a card based on user input (from a select list for instance). In this manner tasks can be seen as akin to HTML forms, but in a much simpler, yet more flexible manner.

The <do> task from the above code snippet simply tells the micro-browser to do something (in this case go somewhere). The type attribute set to accept essentially turns this element into a button to the micro-browser.

What we covered regarding WML is only scratching the surface of what can be done. There are several good books that contain even more in-depth detail regarding WML and WMLScript, but the one I would recommend would be Learning WML & WMLScript by Martin Frost, published by O'Reilly.

The next time we return to the wireless web we'll be taking a step forward and adding even more interactivity to our WAP documents by using WMLScript, a descendant of the ECMAScript standard.

Select Lists, Variables and Tasks  << Page 2 of 3  >>