Basic
Commands
All commands in WML have the form of
<command>....</command>. Commands need to be ended with a
</command>, or else be one of the commands that can be “ended” within the
one set of command brackets, such as <br/>. Also, commands can have many
attributes that go within the first command’s set of brackets, e.g. <command
attribute1=”value1” attribute2=”value2”>. These attributes define the command
or set up different conditions or settings of the command. Some commands have
required attributes that must be there always, as well as optional attributes.
Other commands have only optional attributes or in some cases, no attributes. Appendix I lists
all the WML commands and their associated attributes.
Card
The card command <card>..</card>
defines a card in a WML deck. Each card in a deck must start and end with a card
command. The card command has no required attributes, but has many optional
ones. The id attribute specifies the name associated with that
card, which can be used when transferring between cards in a deck. If the id of a card is “card1”, then when another card transfers to this
card, or refers to it, it uses “#card1”. This allows hyperlinks to be used
between cards using the id of a card as a relative address.
The class attribute is used in order to link the
card to one or more groups. So, cards can have individual id’s but be put in the
same group.
The title attribute specifies the name that
shows up at the top of the dis- play when this card is being executed. This name
the user sees and should define what the card is or does.
Other attributes, onenterforward and onenterbackward, can be used to specify a URL that the browser
moves to when this card is entered going forward or entered going backward. The
URL can also be a relative card address within the same deck.
The ontimer attribute will be discussed more in
the next chapter
under timers, but it specifies a URL for the browser to go to when the timer
command times out.
The newcontext attribute can have a value of
“true” or “false”. When new- context is set to “true”, the
browser will clear its history field, and variables from previous cards will be
removed from the memory. If the newcontext attribute is set to
“false”, the variables from previous cards will not be removed from memory and
the browser will not clear its history field.
The ordered attribute may be either “true” or
“false”. If the ordered attribute is set to “true”, the card
will be placed in linear order according to the WML code order. This feature can
be used when cards must be filled out for a form in a specific order. If set to
“false”, then the browser can determine the order of the presentation elements
of the WAP display. It should be noted that the Nokia WAP Toolkit does not
support the use of the ordered attribute. This makes the
broader point, that due to the large number of different types of wireless
devices and their browsers, not all browsers or platforms support all WML
commands or attributes.
Example 3.11 shows
the use of the id, title and newcontext
attributes of the card command.
Figure 3.7 shows
how example 3.11 looks on a
mobile telephone display.
Do
The do command <do>..</do> starts card tasks.
The <do> element appears as a button or a mobile phone key, with a simple
action-triggered function. The type attribute specifies the
type of action that is to take place and is a required attribute. The type
attribute must have one of the allowed values listed in table 3.2.
Table 3.2
|
Type Values |
Type Attributes Descriptions |
|
Accept |
Affirms acknowledgement |
|
Prev |
Provides backward navigation through the history
stack |
|
Help |
Requests for help(can be context-sensitive) |
|
Reset |
Clears and resets the current state |
|
Options |
Presents an option to the user that she can elect to use or
ignore |
|
Delete |
Deletes the current choice or item |
|
Unknown |
Sets a generic <do> tag which is equivalent to an
empty string |
The label attribute is used to specify the text
that is visible to the user and starts the task related to the command. The
value of the label attribute can be no longer than six
characters, since most browsers display the command- related text behind the
“options” button, and hence restrict it to as little as six characters.
The optional attribute value may be either false
(default) or true. The true value tells the browser that it can exclude the
element from display due to lack of space.
The name attribute is used to give a unique name
to this do event. This can be important if you have multiple do tags in the same
card or deck.
Example 3.12 shows
a deck using the do command. The type specified is “accept”, and therefore when
the button labeled “Forward” is pushed, the action specified within the do
command is done. This command is a go command, and in example 3.12 it goes to card2 when pushed. Figure 3.8 shows the first screen
when card1 is executed, as well as the second screen when card2 is executed.
This example shows the accept attribute which is the most
common attribute used in the <do> command.
Go
The <go> command can be used without an end tag
(<go/>) or with an end tag <go>...</go>. In the second format,
a <postfield/> or a <setvar/> command can be used inside the
<go> tags to specify a value for the variable. One or several
<postfield/> can be used to define name-value pairs when sending
information from a browser to a server. The format of the <go/> command
without an end tag is recommended for use if no other commands are defined
within the <go> command.
The <go> command defines a transfer to a new URL address –
either a deck or a card – as a result of an event. The required href attribute is given a relative or an absolute address. The
absolute address always contains the complete address, starting with the
protocol specification and server name, and ending with subdirectories and the
document name (http://wap.acta.fi/wap/document.wml). In a relative address the
called document is specified relative to the referring document in the directory
hierarchy (subdirectory/document2.wml). If the called document is located on the
same server and in the same directory, then a file name alone is sufficient
(document3.wml). Also, if the transfer is to another card (say card1) in the
same deck, then #card1 is used as the relative address.
If the value of the sendreferer attribute of the
<go> command is true, the browser will include the URL address of the
referring deck in the HTTP request for a new document.
The method attribute can have the value of post
or get. These values refer to the HTTP method of sending data to the server. The
default value is get, but the post method is recommended in CGI programs for
security reasons. Also, it may not be possible to send long strings with the get
method and so this can’t always be used for filling in forms.
The accept-charset attribute is used to define
the character set that the server should use when processing entries. It is
recommended that this attribute always be used when referring to a document or
executable program on a server.
Example 3.13 shows
the <go> command being used to go to a “help” card in the same deck as the
first card. Figure 3.9 shows the
displays for example 3.13. The
second screen occurs when the user pushes the options button, and the third
screen occurs when the select button is pushed.