1 / 17

WML, WMLS

WML, WMLS. More acronyms than you can shake a stick at!. Overview. Fibonacci re-visited WML More samples Templates, access control, and comments WMLS Initialisation control and strings. The Fibonacci Sequence.

kolina
Download Presentation

WML, WMLS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WML, WMLS More acronyms than you can shake a stick at!

  2. Overview • Fibonacci re-visited • WML • More samples • Templates, access control, and comments • WMLS • Initialisation control and strings

  3. The Fibonacci Sequence • The Fibonacci Sequence is a sequence of numbers where each number is the sum of the previous two. • The Fibonacci Sequence was originally devised by a fellow named Fibonacci (surprise) in the 1600’s to model the population growth from a pair of immortal rabbits. • His question was, if every month every pairing of rabbits produced one more rabbit, could he predict how many rabbits he would have after a certain number of months? • This research is of key interest to rabbits and French chefs everywhere. • We’ll write Fib(n) for “The number of Fibonacci rabbits in month n”.

  4. The Fibonacci Sequence • In the first two months, Fib collected rabits: • Fib(1) = 1 • Fib(2) = 1 • During month three he introduced the two rabbits: • Fib(3) = 2 = 1 + 1 • In month four, the two produced one more rabbit: • Fib(4) = 3 = 2 + 1 • In month five, the three produced two more: • Fib(5) = 5 = 3 + 2 • In month six, the five produced three more: • Fib(6) = 8 = 5 + 3

  5. The Fibonacci Sequence • In general, each month, Fib(month) is equal to Fib(the previous month) plus Fib(the month before that): • Fib(1) = 1 • Fib(2) = 1 • Fib(n) = Fib(n-1) + Fib(n-2) • How would you translate this into code? • (Rhetorical question. Answer it in the homework, not now.)

  6. WML - Combining approaches • Let’s look at combining some of what we’ve seen. How would you write a page that let the user choose an image? • We’ll need: • An <img> tag to display the picture; • <select> and <option> tags to pick; • some <p>’s to contain the content; • one <card> to hold them all, and in the <wml> bind them.

  7. WML <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"> <wml> <card id="main" title="How's the Weather?"> <p>Today's weather : <img src="$(name)" alt="$(name)" /></p> <p> <br /> <select name="name"> <option value="sunny.wbmp" onpick="#Main">Sunny</option> <option value="partcldy.wbmp" onpick="#Main">Partly cloudy</option> <option value="cloudy.wbmp" onpick="#Main">Cloudy</option> <option value="rainy.wbmp" onpick="#Main">Rainy</option> </select> </p> </card> </wml>

  8. WML • How did the user’s choice wind up being shown? • Each time the user clicked an <option> tag, that <option> had an onpick event handler. The onpick reloaded the page. • Because each <option> also had a value attribute, that value was assigned to the <select> tag’s variable. • The <select> tag’s variable, $(name), was the file path we used for the <img> tag. • So each time the user clicked, it changed the value of $(name) and refreshed the card; which changed the value used in the src attribute of the <img> tag; which changed the picture that was being displayed. • An interesting note is that the <select> tag picks its value from the first <option> tag, so we get an image showing up on first load.

  9. WML • The <onevent> tag meets the <option> tag: • You can add an <onevent> tag to an <option> tag to enhance the onpick behavior: <select name="name"> <option value="sunny.wbmp"> <onevent type=“onpick”> <refresh> <setvar name=“var1” value=“val1” /> <setvar name=“var2” value=“val2” /> <setvar name=“var3” value=“val3” /> </refresh> </onevent> Sunny </option> ... • This is an effective way of dealing with the fact that the onpick attribute only takes a URL.

  10. WML - Access control • It’s always possible to type in a URL manually. • Wouldn’t it suck if your e-banking web site had a password-check page that forwarded the user to the “transfer your money” page, and the user could just type in the URL for the money-transfer page without checking their password? • <access> and <head> • The <head> tag contains info about a document. The <access> tag belongs in a document’s <head> tag. • The <access> tag limits the domain and filepath that the user can come from to get to this tag: (from the documentation at phone.com:) • domain - The URL domain of other decks that can access cards in this deck. The default value is the domain of the current deck. • path - The URL root of other decks that can access cards in the deck. The default value is "/" (the root path of the current deck) which lets any deck within the specified domain access this deck.

  11. WML - Access control • Access-control example: • <wml> • <head> • <access domain=”luton.ac.uk” path=”/” /> • </head> • <card> • ... • This would define a document which could only be reached by clicking links in documents downloaded from Luton’s web server; you couldn’t link to the document from anyplace else.

  12. WML - Comments • In WMLScript, comments can be either • // single-line comments , or • /* multi-line comments */ exactly like C++ or Java. • There’s no JavaDoc(tm) in WML. • To write comments in WML, use the <!-- and --> markers.

  13. WML Script for initialisation • Last week we saw that you could initialise the value of a variable with the onenterforward event: • <onevent type="onenterforward"> • <refresh> • <setvar name=”Foo” value=”Bar"/> • </refresh> • </onevent> • This can be problematic if you want to change the value of $(Foo) in another card and then the user clicks forward to the first card again (following a link forward, as opposed to hitting the Prev button to go back.)

  14. WML Script for initialisation • An example of things going wrong: <card id="card1" title="Card #1"> <onevent type="onenterforward"> <refresh> <setvar name="myVar" value="first card" /> </refresh> </onevent> <p> myVar = $(myVar) </p> <p> Click for <a href="#card2">second card</a> </p> </card> <card id="card2" title="Card #2"> <onevent type="onenterforward"> <refresh> <setvar name="myVar" value="second card" /> </refresh> </onevent> <p> myVar = $(myVar) </p> <p> Click for <a href="#card1">first card</a> </p> </card> Here the value of myVar will be changed every time the phone loads card1 or card2. That’s not a bug; it’s a feature. But what if you wanted to preserve the change you made in card2, but still have a valid value coming into card1?

  15. WML Script for initialisation • One way to fix things would be to add an ‘initialisation’ card at the front of the document: <card id="card0"> <onevent type="onenterforward"> <go href=“#card1”> <setvar name="myVar" value="first card" /> </refresh> </onevent> </card> <card id="card1" title="Card #1"> <p> myVar = $(myVar) </p> <p> Click for <a href="#card2">second card</a> </p> </card> <card id="card2" .............. Here the value of myVar will be changed every time the phone loads card2, but only once before it loads card1. So the change made in card2 is preserved.

  16. WML Script for initialisation • Another solution to the same problem would be to call a WML Script function: <wml> <card id="card1" title="Card #1"> <onevent type="onenterforward"> <go href="ThingsGoRight.wmls#init()" /> </onevent> <p> myVar = .................. • The WML Script can actually test the var: extern function init() { if (!String.compare(WMLBrowser.getVar("myVar"), "")) WMLBrowser.setVar("myVar", "first card (from WMLS)"); WMLBrowser.refresh(); } • This way the var is only initialised once.

  17. WML Script - Strings • A few words about strings in WML Script: • A “String” is a sequence of characters--letters and numbers--like “bob the string” or “number : 1234” or “!@#%!%”. • The WMLS String Library provides a host of functions to manipulate Strings. • String.compare(S1, S2) : Test for equality • compare(s1,s2) will actually test whether two strings are different. So • if (compare(s1,s2)) ... is testing whether s1 != s2. • To test whether s1 equals s2, use !compare(s1,s2). • Remember that comparison is case-sensitive!

More Related