GWT@Jazoon08 - Part 4/6 - Attention to Detail

1,498 views

Published on

A presentation about GWT which I presentaed at Jazoon '08
Part 4/6 - Attention to Detail

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,498
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
68
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • GWT@Jazoon08 - Part 4/6 - Attention to Detail

    1. 1. <ul><ul><li># 4 </li></ul></ul><ul><ul><li>attention to detail. </li></ul></ul>
    2. 2. make quality evident in everything ...
    3. 3. your Porsche may drive better but ...
    4. 4. create delightfull experiences ...
    5. 5. <ul><ul><li>annoying. </li></ul></ul><ul><ul><li>ajax stuff you can’t bookmark </li></ul></ul><ul><ul><li>broken back buttons </li></ul></ul><ul><ul><li>error type 11 </li></ul></ul><ul><ul><li>page that crashes during submit, what now? </li></ul></ul>
    6. 6. <ul><ul><li>history. </li></ul></ul><ul><ul><li>[ for dummies ] </li></ul></ul>
    7. 7. <ul><ul><li>LISTEN TO HISTORY EVENTS </li></ul></ul><ul><ul><li> public class Example implements EntryPoint, HistoryListener { </li></ul></ul><ul><ul><li> public void onModuleLoad() { </li></ul></ul><ul><ul><li> History.addHistoryListener(this); </li></ul></ul><ul><ul><li> } </li></ul></ul><ul><ul><li> public void onHistoryChanged (String historyToken) { ... } </li></ul></ul><ul><ul><li> } </li></ul></ul><ul><ul><li>CREATE HISTORY EVENTS </li></ul></ul><ul><ul><li> History.newItem(“profile”); = http://localhost:8080/example #profile </li></ul></ul><ul><ul><li> History.newItem(“search”); = http://localhost:8080/example #search </li></ul></ul><ul><ul><li> History.newItem(“edit”); = http://localhost:8080/example #edit </li></ul></ul>
    8. 8. <ul><ul><li>history. </li></ul></ul><ul><ul><li>[ demystified ] </li></ul></ul>
    9. 9. <ul><ul><li>BEHIND THE SCENES </li></ul></ul><ul><ul><li> browser history does not only effect top level pages </li></ul></ul><ul><ul><li> browser history also works for iFrames </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> History maintains a stack of applied tokens </li></ul></ul><ul><ul><li> these tokens can be used to map to specific application state </li></ul></ul><ul><ul><li> background timer which check each ¼ of a second if $wnd.location </li></ul></ul><ul><ul><li> has changed, if so it triggers the History listener (onHistoryChanged) </li></ul></ul>
    10. 10. <ul><ul><li>error handling. </li></ul></ul><ul><ul><li>[ best practices ] </li></ul></ul>
    11. 11. <ul><ul><li>CATCH UNCAUGHT EXCEPTIONS </li></ul></ul><ul><ul><li> catch exceptions at the top-level just before they escape to the browser </li></ul></ul><ul><ul><li> useful for event callbacks, timers, rpc… which are hard to try / catch </li></ul></ul><ul><ul><li> GWT. setUncaughtExceptionHandler (new GWT.UncaughtExceptionHandler() { </li></ul></ul><ul><ul><li> public void onUncaughtException(Throwable e) {         Window.alert(“You thought you could get away didn’t you !!!&quot;);         }     });     </li></ul></ul>
    12. 12. <ul><ul><li>STANDARDIZE EXCEPTION HANDLING </li></ul></ul><ul><ul><li> public abstract class ApplicationAsyncCallback<T> </li></ul></ul><ul><ul><li> implements AsyncCallback<T> { </li></ul></ul><ul><ul><li> public final void onSuccess (T object) { </li></ul></ul><ul><ul><li> onSuccessInternal (object); </li></ul></ul><ul><ul><li> } </li></ul></ul><ul><ul><li> public final void onFailure (Throwable throwable) { </li></ul></ul><ul><ul><li> onFailureInternal (throwable); </li></ul></ul><ul><ul><li>Window.alert(“KABOEMMMM”); </li></ul></ul><ul><ul><li> } </li></ul></ul><ul><ul><li> protected void onSuccessInternal (T object) {} </li></ul></ul><ul><ul><li>protected void onFailureInternal (Throwable throwable) {} </li></ul></ul><ul><ul><li> } </li></ul></ul>
    13. 13. <ul><ul><li>LOG, LOG, LOG, LOG EVERYWHERE (1/4) </li></ul></ul><ul><ul><li>  Log.debug(“Some log message”); </li></ul></ul><ul><ul><li> public class Log { </li></ul></ul><ul><ul><li> private static final Logger logger = </li></ul></ul><ul><ul><li> GWT.isScript() ? new com.FireBugLogger() : new HostedModeLogger(); </li></ul></ul><ul><ul><li> public static void debug (String message) { log(DEBUG, message); } </li></ul></ul><ul><ul><li> protected static void log (Level level, String message) { </li></ul></ul><ul><ul><li>if (enabled && level.getWeight() <= getMaxLevel(). getWeight()) { </li></ul></ul><ul><ul><li>switch (level) { </li></ul></ul><ul><ul><li>case ERROR: logger.error(message); break; </li></ul></ul><ul><ul><li>case WARN: logger.warn(message); break; </li></ul></ul><ul><ul><li>case INFO: logger.info(message); break; </li></ul></ul><ul><ul><li>case DEBUG: logger.debug(message); break; </li></ul></ul>
    14. 14. <ul><ul><li>LOG, LOG, LOG, LOG EVERYWHERE (2/4) </li></ul></ul><ul><ul><li> // request log level at runtime  http://localhost:8080/x.html?log.level=error </li></ul></ul><ul><ul><li> public static native String getLoglevel () /*-{ </li></ul></ul><ul><ul><li>var level; </li></ul></ul><ul><ul><li>var args = $wnd.location.search ; </li></ul></ul><ul><ul><li>var startLang = args.indexOf(&quot; log.level &quot;); </li></ul></ul><ul><ul><li>if (startLang >= 0) { </li></ul></ul><ul><ul><li>var value = args.substring(startLang); </li></ul></ul><ul><ul><li>var begin = value.indexOf(&quot;=&quot;) + 1; </li></ul></ul><ul><ul><li>var end = value.indexOf(&quot;&&quot;); </li></ul></ul><ul><ul><li>if (end == -1) { </li></ul></ul><ul><ul><li>end = value.length; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>level = value.substring(begin, end); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>return level; </li></ul></ul><ul><ul><li>}-*/; </li></ul></ul>
    15. 15. <ul><ul><li>LOG, LOG, LOG, LOG EVERYWHERE (3/4) </li></ul></ul><ul><ul><li> </li></ul></ul><ul><ul><li> public class FireBugLogger implements Logger { </li></ul></ul><ul><ul><li> private boolean fireBugInstalled = false; </li></ul></ul><ul><ul><li> protected FireBugLogger() { </li></ul></ul><ul><ul><li>checkIfFireBugInstalled () ; </li></ul></ul><ul><ul><li> } </li></ul></ul><ul><ul><li> protected native void checkIfFireBugInstalled () /*-{ </li></ul></ul><ul><ul><li> this.@com.FireBugLogger::fireBugInstalled = ( typeof console != 'undefined' ); </li></ul></ul><ul><ul><li> }-*/; </li></ul></ul><ul><ul><li> public native void debug (String message) /*-{ </li></ul></ul><ul><ul><li>if (this.@com.FireBugLogger::fireBugInstalled) console.debug(message) ; </li></ul></ul><ul><ul><li> }-*/; </li></ul></ul>
    16. 16. <ul><ul><li>LOG, LOG, LOG, LOG EVERYWHERE (4/4) </li></ul></ul><ul><ul><li> public class HostedModeLogger implements Logger { </li></ul></ul><ul><ul><li> public void debug (String message) { </li></ul></ul><ul><ul><li>log(toMessageWithLineInformation(&quot;DEBUG&quot;, message)); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li> public void log (String message) { GWT.log(message, null); } </li></ul></ul><ul><ul><li>private String toMessageWithLineInformation (String logLevel, String message) { </li></ul></ul><ul><ul><li>StackTraceElement line = new Throwable().getStackTrace()[4]; </li></ul></ul><ul><ul><li>return (logLevel + &quot; &quot; + toLine(line) + &quot;: &quot; + message); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>private String toLine (StackTraceElement line) { </li></ul></ul><ul><ul><li>return line.getClassName() + &quot;(&quot; + line.getLineNumber() + &quot;)&quot;; </li></ul></ul><ul><ul><li>} </li></ul></ul>
    17. 17. <ul><ul><li>what’s wrong with the log example? </li></ul></ul>
    18. 18. <ul><ul><li>AUTOMATED USER ACCEPTANCE TESTS WITH SELENIUM </li></ul></ul><ul><ul><li> your code </li></ul></ul><ul><ul><li> Label firstnameLabel = new Label(); </li></ul></ul><ul><ul><li> label.ensureDebugId(“firstnameLabel”); // if not enabled  does nothing </li></ul></ul><ul><ul><li> enable debug mode – go Selenium gooooo….. </li></ul></ul><ul><ul><li> <inherits name=“com.google.gwt.user.Debug”/> // DOM.setElementProperty(…) </li></ul></ul><ul><ul><li> under the hood – UIObject </li></ul></ul><ul><ul><li> private static DebugIdImpl debugIdImpl = GWT.create(DebugIdImpl.class); </li></ul></ul><ul><ul><li> public static void ensureDebugId(Element elem, String id) { </li></ul></ul><ul><ul><li> debugIdImpl.ensureDebugId(elem, id); </li></ul></ul><ul><ul><li> } </li></ul></ul>
    19. 19. <ul><ul><li>MAARTENVOLDERS. com </li></ul></ul><ul><ul><li>PASSIONATE ABOUT PEOPLE AND TECHNOLOGY </li></ul></ul>

    ×