htmlpage/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageController.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 11 Oct 2012 06:15:22 -0700
branchemul
changeset 100 029e6eed60e9
child 104 1376481f15e7
permissions -rw-r--r--
Now we are able to change a title of a page inside of a browser
     1 package org.apidesign.bck2brwsr.htmlpage;
     2 
     3 import org.apidesign.bck2brwsr.htmlpage.api.OnClick;
     4 import org.apidesign.bck2brwsr.htmlpage.api.Page;
     5 
     6 /** Trivial demo for the bck2brwsr project. First of all start
     7  * with <a href="TestPage.html">your XHTML page</a>. Include there
     8  * a script that will <em>boot Java</em> in your browser.
     9  * <p>
    10  * Then use <code>@Page</code> annotation to 
    11  * generate a Java representation of elements with IDs in that page.
    12  * Depending on the type of the elements, they will have different 
    13  * methods (e.g. <code>PG_TITLE</code> has <code>setText</code>, etc.).
    14  * Use <code>@OnClick</code> annotation to associate behavior
    15  * with existing elements. Use the generated elements
    16  * (<code>PG_TITLE</code>, <code>PG_TEXT</code>) to modify the page.
    17  * <p>
    18  * Everything is type-safe. As soon as somebody modifies the page and
    19  * removes the IDs or re-assigns them to wrong elements. Java compiler
    20  * will emit an error.
    21  * <p>
    22  * Welcome to the type-safe HTML5 world!
    23  *
    24  * @author Jaroslav Tulach <jtulach@netbeans.org>
    25  */
    26 @Page(xhtml="TestPage.html", name="TestPage")
    27 public class PageController {
    28     @OnClick(id="pg.button")
    29     static void updateTitle() {
    30         TestPage.PG_TITLE.setText(TestPage.PG_TEXT.getValue());
    31     }
    32 }