Print

Learning WML: Tasks and Events
Pages: 1, 2, 3, 4, 5, 6

The <refresh> Task

The <refresh> task is the simplest task that actually does something. Its effect is simply to perform the variable assignments specified by its <setvar> elements, then redisplay the current card with the new values. The <go> and <prev> tasks perform the same action just before displaying the new card.

The <refresh> task doesn't take any attributes.

The <refresh> task is most often used to perform some sort of "reset" action on the card. Example 3-1 shows how this could be done. The <input> elements prompt the user to enter strings and then store the strings into the variables specified in their name attributes (see Chapter 4 for more information). There is also a <go> task using the POST method to submit the login and password information to a server for processing.

Example 3-1: A Reset Button

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC
    "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.wapforum.org/DTD/wml_1.1.xml">
 
<wml>
    <card title="Reset button example">
        <!-- Read login and password from user. -->
        <p>Login:    <input name="login"/></p>
        <p>Password: <input name="password"/></p>
 
        <!-- Submit button sends data to server. -->
        <do type="accept" label="Submit">
            <go href="login.cgi" method="post">
                <postfield name="l" value="$(login)"/>
                <postfield name="p" value="$(password)"/>
            </go>
        </do>
 
        <!-- Reset button clears login and password. -->
        <do type="reset" label="Reset">
            <refresh>
                <setvar name="login" value=""/>
                <setvar name="password" value=""/>
            </refresh>
        </do>
    </card>
</wml>

The <noop> Task

The purpose of the <noop> task is to do nothing (no operation). This may seem particularly useless: why would anyone want a task that doesn't do anything?

The only real use for this task is in connection with templates (discussed in more detail in Chapter 6, WML Decks, Templates, and Cards). However, it can also be specified anywhere a task is required.

The <noop> task is the only exception to the rule that tasks can set variables. It can't set variables and can't even contain any <setvar> elements. If you want a task to just set variables and not change the current card, use the <refresh> task.

The <noop> task doesn't take any attributes.

Because the <noop> task takes no attributes and can't even contain any <setvar> elements, it always looks the same in use:

<noop/>

Pages: 1, 2, 3, 4, 5, 6

Next Pagearrow