UP.SDK Developer's Guide

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Introduction to WML
Section 9 out of 61 total sections , Section 3 out of 6 sections in this chapter


Navigating between cards and decks

Like conventional Web sites, a WML service usually consists of a set of screens that present information with which users can interact. In WML, these screens are defined as a set of one or more cards. The actual correspondence between cards and screens depends on the device display size, as well as how you define your cards. On larger devices, the UP.Browser may present a card as a single screen. On smaller devices, the same card may appear as multiple screens. The key to constructing an efficient and easy-to-use WML service is determining the best way to:

Before discussing how to navigate between multiple cards, it is helpful to look at a simple synopsis of the <card> element:

<card id="name">


IMPORTANT     For a complete synopsis of the <card> element and its attributes, see the WML Language Reference.



Specifying URLs

As in HTML, navigation in WML occurs by specifying URLs. To navigate between multiple cards and decks, you simply specify the URL you want to open.

To navigate to a particular card, specify a URL with the following syntax:

deck_URL#card_id

If you do not specify a card, the device automatically displays the first card in the deck.

For example, if the deck services/mydeck.wml has the following definition,

you would specify services/mydeck.wml (the URL of the deck) to navigate to the first card. To navigate to the third card, you would specify the URL:

services/mydeck.wml#card3

If you want to navigate from one card to another card in the same deck, you can also use a relative URL and simply reference it as #card_id.


Specifying CGI arguments

Specifying CGI arguments within URLs deserves special attention because two important differences exist between HTML and WML:



The history stack

The UP.Phone maintains a history of the cards the user visits. Each time the user navigates forward to a card, the UP.Phone pushes it on to the history stack. When the user invokes the PREV mechanism, the UP.Phone pops the current card off the history stack and returns to the previous card.

UP.Phone history operation is similar to that of most Web browsers, with the exception that users cannot navigate forward through the history stack--the current card is always at the top of the stack.

For example, suppose the deck described above defines the following cards:

Figure  1-1.     Card history stack

Figure 1-1 illustrates how the history stack changes as the user navigates between various cards.

To view the history stack in the UP.Simulator, choose Info>History. Note that the UP.Simulator displays the history stack from bottom to top in the Phone Information window--in other words, from least-recently visited to most-recently visited. So, for example, the history stack for the Menu card shown above would appear as follows:



Defining actions for multiple cards

As described above, the <do> element lets you associate an action (for example, going to a particular URL) with a mechanism for invoking it (for example, pressing the ACCEPT or OPTIONS function key). You can define multiple <do> statements for a card, each of which assigns a task to a specific key or user interface mechanism.

In some cases, you may want to assign the same task to a particular key for every card in a deck. One way to accomplish this is to specify identical <do> statements within each <card> statement. As shown in the following example, a more efficient way is to use the <template> element to define behavior that applies to the entire deck:

Figure  1-2.    

1    <wml>
2    <template>
3        <do type="options" label="Moon">
4            <go href="moon.wml"/>
5        </do>
6    </template>
7    <card>
8        <do type="accept" label="Tues">
9            <go href="#tues"/>
10        </do>
11        <p>
12          Current temps <br/>
13          Hi: 60 <br/>
14          Lo: 28
15        </p>
16    </card>
17    <card id="tues">
18        <do type="accept" label="Wed">
19            <go href="#wed"/>
20        </do>
21        <p>
22          Tuesday temps <br/>
23          Hi: 78 <br/>
24          Lo: 36
25        </p>
26    </card>
27    <card id="wed">
28      <p>
29        Wednesday temps <br/>
30        Hi: 80 <br/>
31        Lo: 40
32      </p>
33    </card>
34    </wml>

Figure  1-3.     moon.wml

1    <wml>
2    <card>
3      <p>
4         Next full moon: <br/>
5         6-27-1999
6      </p>
7    </card>
8    </wml>

As illustrated in Figure 1-4, the <template> statement instructs the UP.Browser to do the following for every card in the deck:

The <do> statements apply only to the cards for which they are defined. The <do> statement for the first card instructs the UP.Browser to:

The <do> statement for the second card instructs the UP.Browser to:

Figure  1-4.     Deck with multiple cards

The third card in the deck has no <do> statement because the default action for the ACCEPT key is to return to the previous card. If the user presses the ACCEPT key, the UP.Browser automatically displays the previous card. For more information about the default actions for different keys, see the WML Language Reference.


Overriding deck-level actions

As shown in the previous example, you can define <do> statements at both the deck level (using the <template> element) and the card level. A deck-level <do> statement applies to all cards in the deck. A card-level <do> statement applies to the individual card only. Card-level definitions override (or shadow) deck-level definitions if both statements have the same NAME or are of the same TYPE if you do not specify a NAME.

The following example (illustrated in Figure 1-5) defines a deck-level <do> statement for the ACCEPT key. The first card in the deck specifies a <do> statement with the same type attribute, so the card-level binding overrides the deck-level binding for that card. The deck-level binding still applies to the second and third cards in the deck.

Figure  1-5.     Card-level action that supersedes deck-level action



Using multiple decks

The sample deck on page 14 also illustrates that card navigation can span multiple decks. The card that displays the date of the next full moon could have been defined in the same deck as the other cards. Because of packet size limitations, however, it often makes sense to break cards into separate decks.


IMPORTANT     The size limit for a deck after the UP.Link Server compiles it is 1492 bytes.1 Because dynamic WML services typically generate responses of varying length, you should limit the size of your decks to 1200 bytes. To view the size of a compiled deck, load it in the UP.Simulator--the UP.Simulator will display the deck size in the Phone Information Window.

As shown in line 4 of Figure 1-2, you can use a relative URL to specify another deck in the same directory. As mentioned earlier, you do not have to specify a card name when navigating to a different deck unless you want to go to a card other than the first card in the deck.



Defining links

Anchored links provide another mechanism for letting users navigate between cards and decks. Unlike the more generic <do> element in which you can bind a task to a variety of user interface mechanisms, users always invoke the task associated with an anchored link by pressing the ACCEPT key. As in HTML, WML links are anchored to text which the device displays in a different manner than surrounding text. WML links can also be anchored to the <img> element. The following is a synopsis of the <anchor> element, which defines an anchored link:

Component  Description 
title  

Specifies a label for the ACCEPT key (optional). When users scroll to the link, this label overrides any other label defined for that key in the current card or deck. 

task  

Specifies the task to execute, either <go>, <prev>, or <refresh>

text  

Specifies the text to which the link is anchored. 

<img>  

Specifies the image to which the link is anchored. 

There is also a short form syntax for anchors. It uses the <a> tag instead of the <anchor> tag and can only be used to define (implied) go tasks that require a URL specification:

The following WML defines a card with several links (shown in Figure 1-6).

Figure  1-6.     Card with anchored links

NOTE     When users scroll to an anchored link, the ACCEPT key label (and task) specified by the <a> element takes precedence over the <do> element binding. Users can access the "default" action for the ACCEPT key by positioning the cursor on a line other than an anchored link.


[Cover] [Previous Section] [Next Section] [Index]


1 Compilation normally decreases the size of a deck--it may, however, increase the size if the deck contains text with many words and spaces (since the UP.Link Server tokenizes each word as a null-terminated string and each space as a byte code).

Copyright © 2000, Phone.com Inc. All rights reserved.
Please send comments and questions to doc-comments@corp.phone.com.