Learning WML - Navigation, User Input, and Graphics, Page 2
Events
You can also set up navigation that is caused by a particular event. The <onevent> element provides several possible actions triggered by one or more intrinsic events.
The <onevent> tag has the following format:
<onevent type="type"> task</onevent>
The "type" can be one of the following:
| Type | Event |
| onpick | User selects or deselects an <option> item. |
| onenterforward | User navigates to a card in a forward manner (e.g., from a <go> or other link) |
| onenterbackward | User navigates to a card in a backward manner (e.g., from a <prev> element or Back command) |
| ontimer | A specified <timer> element expires |
The "onenter" types can be used to display or omit particular information depending on how the user navigated to the card, or to force a refresh of dynamic information if the user reached the card by going backward (thereby getting the card from the cache and not a fresh copy from the server).
The "onpick" type is used when the <onevent> is nested within an <option> element to provide an action when the option is selected.
The "ontimer" type is used to provide a task at a particular time, independent of user actions (refreshing a page, moving to another page, etc).
The various tasks that can be used with the <onevent> element are described in the following table.
| Task | Use |
| <go> | Navigates to a new card. |
| <prev> | Navigates to the previous card. |
| <noop> | Performs no task (no operation). |
| <refresh> | Refreshes the current card's content. |
| <exit> | Exits the current context. * |
| <spawn> | Spawns a child task. * |
| <throw> | "Throws" an exception that can be caught by an |
| optional | <catch> element. * |
* These tasks are specific to the Openwave browser. See the developer documentation at http://developer.openwave.com for more information.
The "ontimer" event can be used to display a splash screen (containing welcoming or copyright information), or to automatically return to a card after displaying an error. Its also very useful for refreshing a card to display up-to-date dynamic data.
In the following example, the deck displays a splash screen before the main menu:
<?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="splash" title="Welcome!"><onevent type="ontimer"> <go href="#main" /></onevent><timer name="delay" value="50"/><p mode="wrap">Welcome to ACME Incorporated.</p></card><card id="main" title="Main Menu"><p>Main menu here...</p></card></wml>
Note: The <timer> element's value parameter is measured in tenths of a second, so our splash screen stays active for 5 seconds (50 tenths).
Tip: The <card> element includes an optional "ontimer" parameter, which alleviates the need for a separate <onevent> element. Using this parameter, the above example could be shortened as follows:
. . . <card id="splash" title="Welcome!" ontimer="#main"> <timer name="delay" value="50"/> . . .
