Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

WAP for Java developers

Develop WAP applications with Java servlets and JSP

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 3 of 6

The genesis of WML

The basic unit of WML is the card that specifies a single interaction between the user and the user agent. Multiple cards are grouped together in decks. A deck is the topmost element of a WML document. When the user agent receives a deck (by downloading the complete deck), it activates only the first card in the deck. Listing 1 shows a sample WML document with a single card:

Listing 1. Example1.wml

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>  
  <card id="MyFirstCard" title="First Card">    
    <p align="center">
      My First WML Example
    </p>
  </card>
</wml>


When viewed on a WAP-enabled phone, Listing 1 is rendered and displayed as shown in Figure 4.

Figure 4. The result of
Example1.wml



As I mentioned before, WML is based on XML. Therefore, a deck has to be a valid XML document, which implies that a WML document (as the one shown in Listing 1) should start with the standard XML header and the reference to the WML DTD. The <p> tag delimits a paragraph and must be used to wrap any text you want to display.

Now, take a look at an example that has two cards and uses other WML features. Listing 2 shows the Ottawa City Guide example.

Listing 2. Example2.wml

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
  <card id="city" title="Ottawa Guide">
    <p align="center"></p>
    <p>
      <a title="Business" href="#business">Business</a><br/>
      <a title="Education" href="#education">Education</a><br/>
      <a title="Entertainment" href="#entertainment">Entertainment</a><br/>
      <a title="Restaurants" href="#food">Restaurants</a><br/>
      <a title="Shopping" href="#shopping">Shopping</a><br/>
      <a title="Travel" href="#travel">Travel</a><br/>
      <a title="Weather" href="#weather">Weather</a><br/>
    </p>
  </card>
<card id="food" title="Restaurants">
    <p><img src="food.bwmp" alt="logo"/></p>
<p>
<a title="Canadian" href="#canadian">Canadian</a><br/>
      <a title="Chinese" href="#chinese">Chinese</a><br/>
      <a title="Continental" href="#continental">Continental</a><br/>
      <a title="French" href="#french">French</a><br/>
      <a title="German" href="#german">German</a><br/>
      <a title="Greek" href="#greek">Greek</a><br/>
      <a title="Italian" href="#italian">Italian</a><br/>
    </p>
</card>
</wml>


This example was developed using the Ericsson WapIDE (WAP integrated development environment). WapIDE is shown in Figure 5 along with the output of Listing 2.

Figure 5. Ericsson's WapIDE.
Click on thumbnail to view
full image (53k)

The example in Listing 2 has two cards: city and food. When a device receives this deck, it loads the first card automatically as shown in Figure 6.

Figure 6. The first card



Once the city card is loaded, you can navigate through it using the soft key on your device. Figure 7 shows what happens when the Restaurants option is selected.

Figure 7. The Restaurants option



Navigation in this example is implemented using anchors (<anchor>), which are the WML counterpart of <A> tags in HTML. An anchor can be defined as:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources