SlideShare una empresa de Scribd logo
1 de 56
Descargar para leer sin conexión
Building Rich Internet Applications
Using Google Web Toolkit (GWT)

Karthik Shyamsunder


October 2008




                      Karthik Shyamsunder
Who am I?


    + Karthik Shyamsunder
      ▪ Principal Engineer, VeriSign Inc.
      ▪ Application Architect for the VeriSign Naming Division
      ▪ Adjunct Faculty at Johns Hopkins University
      ▪ Speak at conferences on Architecture, Security, Performance, Distributed
        Computing, Language/Design




2
                       VeriSign Proprietary and Confidential Information
Overall Goal of this Session




    1. Introduce you to the GWT framework and
       application development
    2. Discuss key features in GWT that will
       allow you to build no compromise AJAX
       applications


3
                  VeriSign Proprietary and Confidential Information
Agenda

    + RIA Technologies, Frameworks and GWT
    + GWT Quickstart
    + GWT Architecture
    + Key GWT Features
    + Summary
    + Q&A




4
                       VeriSign Proprietary and Confidential Information
Agenda

    + RIA Technologies, Frameworks and GWT
    + GWT Quickstart
    + GWT Architecture
    + Key GWT Features
    + Summary
    + Q&A




5
                       VeriSign Proprietary and Confidential Information
What are Rich Internet Applications?
+    Web applications that have the features and
                                                                              Backend
     functionality of traditional desktop applications
                                                                              Processes

+     Typically do the following:                                            Server Logic
     ▪ run in a web browser, or do not require software
        installation
     ▪ run locally in a secure environment called a                            Server
        sandbox


+    Typically transfer the processing necessary for the
     user interface to the web client but keep the bulk of
     the data back on the application server
                                                                                (Sandbox
+    Make asynchronous/synchronous calls to the                               Client Engine)

     backend based on user actions/events

+    “Thick Client” Application

                         VeriSign Proprietary and Confidential Information
Technologies for Building RIAs

+   Several technologies available for building
    Rich Internet Applications                                         Backend
                                                                       Processes


+    Key Technologies for building RIAs                               Server Logic
    ▪ Adobe Flex
    ▪ Microsoft Silverlight                                             Server
    ▪ Java Applets/WebStart
    ▪ AJAX




+    Other Technologies and Frameworks for
                                                                         (Sandbox
     building RIAs                                                     Client Engine)
    ▪ Java FX
    ▪ Open Laszlo



                  VeriSign Proprietary and Confidential Information
Building RIAs using Java EE and AJAX

We can classify building applications in AJAX into 2 :
    1. Client Side AJAX Development
        – Presentation using HTML/JSP pages using client side frameworks such as
           Scriptaculous, JQuery, Dojo client side components
        – Presentation logic using JavaScript
        – Server Side development using traditional Java EE Servlets/Services
           exposing backend services as REST, XML RPC Web Services
        – Call backend business logic in the background using the JavaScript
           language and XMLHttpRequest object built into the browser

    2. Server Side AJAX Development
        – Presentation using component frameworks JSTL tag libraries such as JBoss
           RichFaces, Icesoft Icefaces built on on top of JSF
        – Presentation logic done as event handlers in JSF component model
        – Call to backend business logic using JSF event Model




                    VeriSign Proprietary and Confidential Information
Challenges with typical AJAX development
    + JavaScript
        ▪ Not a strongly typed language
        ▪ Static Type checking?
        ▪   Code completion?
        ▪   Runtime-only bugs
    + Browser compatibilities = “if/else soup”
        ▪   OK, we have frameworks
        ▪   Too many frameworks!
    + Juggling multiple languages (JavaScript, JSP tags,
      Java, XML, HTML etc.)
        ▪   Less modularization
        ▪   Maintenance nightmare
    + Poor debugging
        ▪   Window.alert(), Firebug
        ▪   But what about end to end
    + Back button
    + Limited IDE support


9
                               VeriSign Proprietary and Confidential Information
Introducing Google Web Toolkit




10
                  VeriSign Proprietary and Confidential Information
Introducing GWT
     + What is GWT?
        ▪ GWT is an open source Java development framework
        ▪ Provides set of tools for building AJAX apps in the Java language


     + What makes GWT interesting?
        ▪ Write, run, test, and debug everything in JAVA!


     + GWT ≠ applets
        ▪ GWT converts your Java source into equivalent JavaScript


     + Is GWT a compiler?
        ▪ GWT has a compiler, but it has lot more to offer…




11
                         VeriSign Proprietary and Confidential Information
Why Use Java Language for AJAX Development?

     + Static type checking in the Java language boosts productivity while
       reducing errors


     + Common JavaScript errors (typos, type mismatches) are easily
       caught at compile time rather than by users at runtime


     + Code prompting/completion is widely available


     + Automated Java refactoring is pretty snazzy these days


     + Java-based OO designs are easier to communicate and understand,
       thus making your AJAX code base more comprehensible with less
       documentation.
12
                        VeriSign Proprietary and Confidential Information
Advantages of GWT

     + No need to learn/use JavaScript language
        ▪ Leverage Java programming knowledge you already have

     + No need to handle browser incompatibilities and quirks
        ▪ GWT handles them for you

     + No need to learn/use DOM APIs
        ▪ Use Java APIs

     + No need to handle forward/backward buttons browser-history
        ▪ GWT handles it for you

     + No need to build commonly used Widgets
        ▪ Most of them come with GWT

     + Can send complex Java types to/from the server
        ▪ Data gets serialized across network



13
                        VeriSign Proprietary and Confidential Information
Advantages of GWT

     + Leverage various tools of Java programming language for
       writing/debugging/testing
         ▪ For example, NetBeans or Eclipse


     + Internationalization
         ▪ GWT includes a flexible set of tools to help you internationalize your
           applications and libraries
         ▪ GWT internationalization support provides a variety of techniques


     + JUnit integration
         ▪ GWT's direct integration with JUnit lets you unit test both in a debugger
           and in a browser and you can even unit test asynchronous RPCs


     + Support by major company
         ▪ From the company that popularized Ajax in the first place
         ▪ Company won't go away like perhaps with AjaxTags

14
                           VeriSign Proprietary and Confidential Information
Disadvantages of GWT

     + Only for Java developers
        ▪ Most Ajax environments do JavaScript on the client and have a choice
           for the server. GWT is based entirely around Java.
     + Big learning curve
        ▪ Java developers can deploy with AjaxTags in just a few minutes,
           whereas it takes much longer to get anything running with GWT.
     + Cumbersome deployment
        ▪ Clumsy and poorly documented process to deploy on a regular Java-
           based Web server.
     + Nonstandard approach to integrate JavaScript
        ▪ You never put direct JavaScript in your HTML. Instead, you use JSNI to
           wrap JavaScript in Java.
            – Very powerful in the long run, but hard to get used to at first.
     + Unusual approach
        ▪ Fundamentally different strategy than all other Ajax environments
           makes evaluation and management buyoff harder

15
                          VeriSign Proprietary and Confidential Information
Agenda

     + RIA Technologies, Frameworks and GWT
     + GWT Quickstart
     + GWT Architecture
     + Key GWT Features
     + Summary
     + Q&A




16
                     VeriSign Proprietary and Confidential Information
Downloading and Installing GWT
     + Official Site for GWT is http://code.google.com/webtoolkit/
     + Downloading GWT
         ▪ You can download the latest version of software from
           http://code.google.com/webtoolkit/download.html
         ▪ Licensed under Apache 2.0 open source license scheme
         ▪ Latest version of the software is GWT 1.5

     + Installing GWT
         ▪ Extract the ZIP file into wherever you want to install the toolkit
         ▪ That’s it!

     + Setting up the development environment
         ▪ Add {INSTALL-DIR}gwt-windows-1.5.2 to your PATH
         ▪ This is so that the many of the toolkit commands are available

     + Since GWT is java based tool ensure that you have JDK 1.5 or
       above and JAVA_HOME is set

17
                           VeriSign Proprietary and Confidential Information
Application Development Steps
     + Create an Eclipse application
        ▪ Use projectCreator and applicationCreator scripts
        ▪ You can make non-Eclipse projects also, but the tutorial examples
           assume Eclipse. I use MyEclipse, but it is similar in both versions.

     + Edit auto-generated HTML file
        ▪ Called AppName.html
           – Under src/package.../public folder in Eclipse
        ▪ Give ids to regions where controls will be placed

     + Edit auto-generated Java application class
        ▪ Class: package...client.AppName
            – Under src folder in Eclipse
        ▪ Method: onModuleLoad
        ▪ Create controls and give them event handlers
        ▪ Insert controls into HTML page
            – RootPanel.get(quot;htmlIDquot;).add(control);

18
                          VeriSign Proprietary and Confidential Information
Application Development Steps
     1. Make sure PATH includes GWT install directory
         ▪   Or specify full path for scripts

     2. Make a temporary directory for your project
         ▪   Directory name is arbitrary

     3. Make a blank Eclipse project
                                                                                Names must match
         ▪   DOS> projectCreator –eclipse GwtTestProject

     4. Make a starting-point application
         ▪   DOS> applicationCreator –eclipse GwtTestProject
                  myPackage.client.GwtTestApplication                            Name of driver class
                                                                                 that will be created.
     5. Start Eclipse and import project                                         Rightmost package
                                                                                 name must be quot;clientquot;.
         ▪   File > Import > Existing Projects into Workspace
              – Browse to directory from (2) above and click quot;Finishquot;
              – If you specify quot;copy filesquot; (usual approach), then delete the
                  temporary directory from (2) above


19
                            VeriSign Proprietary and Confidential Information
Application Development Steps


                                    Starting-point HTML file. You will edit this extensively.

                                                   When you make server-side code, register servlet in here.

                                              Client-side code must be in quot;clientquot; package. Server-
                                              side code can also import and call classes in this
                                              package (other than main app). All code in this
                                              package will eventually get translated into JavaScript.


                                             Starting point client-side code. You will edit this extensively.


                                               After you have finished testing and debugging, you can
                                               double-click this to generate www directory containing HTML
                                               and JavaScript that can run in a regular browser. But an
                                               easier way to build these files is to run in hosted mode and
                                               then click Compile/Browse (see later slides).


                          Not needed if you run within an IDE.


20
                 VeriSign Proprietary and Confidential Information
Agenda

     + RIA Technologies, Frameworks and GWT
     + GWT Quickstart
     + GWT Architecture
     + Key GWT Features
     + Summary
     + Q&A




21
                        VeriSign Proprietary and Confidential Information
GWT Architecture




22
              VeriSign Proprietary and Confidential Information
Google Web Toolkit - Architecture


 Server Side   Client Side
    .java         .java
                                                                         Web/Application
                                                                             Server


                                                                     D
                                                                 E
  Java          GWT                                          P
                                                         L                             HTTP/
Compiler       Compiler                              O                                 REST/
                                                 Y                                     Web Services
                                                                                       XML/
                                                                                       JSON/
                                                                         (AJAX Runtime
                                                                                       RPC
                                                                            Engine)
   .class      .html          .html
                 .html           . js




                     VeriSign Proprietary and Confidential Information
Running GWT Applications
Hosted Mode
     ▪   Application is run as Java byte
         code within the JVM
     ▪   Developers spend most of their
         time in hosted mode to take
         advantage of Java's debugging
         facilities and other features

+ Web mode
     ▪   Application is run as pure
         JavaScript and HTML, compiled
         from your original Java source
         code with the GWT Java-to-
         JavaScript compiler
     ▪   You deploy this JavaScript and
         HTML to production, so end users
         sees web version of your app


24
                         VeriSign Proprietary and Confidential Information
Agenda

     + RIA Technologies, Frameworks and GWT
     + GWT Quickstart
     + GWT Architecture
     + Key GWT Features
     + Summary
     + Q&A




25
                        VeriSign Proprietary and Confidential Information
What browsers does GWT Support?
     + Officially as of mid 2008, GWT supports the following browsers:

        ▪ Firefox 1.0, 1.5, 2.0 and 3.0




        ▪ Internet Explorer 6 and 7




        ▪ Safari 2 and 3




        ▪ Opera 9.0


26
                         VeriSign Proprietary and Confidential Information
GWT Widgets and Layout




27
                VeriSign Proprietary and Confidential Information
UI components & Event Programming Model
 + Programming model similar UI frameworks such as Swing
 + Primary difference between Swing and GWT is here widgets are
   dynamically transformed to HTML rather than pixel-oriented graphics
 + Using widgets makes it much easier to quickly build interfaces that will
   work correctly on all browsers
         Button btnOk = new Button(“OK”);
         CheckBox married= new CheckBox(“Married”);

 + Events in GWT use the quot;listener interfacequot; model similar to other user
   interface frameworks (like Swing)
        btnOk.addClickListener(new MyClickListener());

 + Possible to manipulate the browser's DOM directly using the DOM
   interface, but better to use Java classes from Widget library



28
                      VeriSign Proprietary and Confidential Information
Style with CSS
 + Each widget class has an associated style name that binds it to a
   CSS rule
      ▪   For example GWT Button has a style called “gwt-Button”

 + A widget’s style name can be set using
      ▪   setStyleName(String)

 + Also possible to assign an id to a particular component to create a
   CSS rule that applies to just one component
      ▪   <div id=“my-button-id”/>

 + To set the id for a GWT widget, retrieve its DOM Element and then set
   the id attribute as follows
      ▪   Button b = new Button();
      ▪   DOM.setElementAttribute(b.getElement(), quot;idquot;, quot;my-button-idquot;)

 + Allows you to reference a specific widget in a stylesheet as follows
      #my-button-id { font-size: 100%; }

29
                          VeriSign Proprietary and Confidential Information
Style with CSS (Contd.)
 + Including Stylesheets in the HTML Host Page
      ▪   Stylesheets are placed in the module's public path
      ▪   Refer to them them by simply using a <link> tag in the page:
           <link rel=quot;stylesheetquot; href=quot;mystyles.cssquot; type=quot;text/cssquot;/>

 + GWT comes with 3 default visual themes that you can choose from
      ▪   Standard, Chrome, and Dark

 + By default new applications use standard theme
 + Other themes can be selected by adding inherits tag in the
   Main.gwt.xml file
      <inherits name='com.google.gwt.user.theme.standard.Standard'/>
      <inherits name=quot;com.google.gwt.user.theme.chrome.Chromequot;/>
      <inherits name=quot;com.google.gwt.user.theme.dark.Darkquot;/>




30
                          VeriSign Proprietary and Confidential Information
Third Party Visual Builder - Instantiations
 + Instantiations, a software company in Portland Oregon, USA
 + Has a product called GWT Designer which is a powerful
   bi0directional WYSIWYG tool that may be worth looking into




31
                     VeriSign Proprietary and Confidential Information
RPC
 + RPCs give you the opportunity to move all UI logic to the client, thus
     ▪   Geatly improving performance
     ▪   Reducing bandwidth
     ▪   Reducing web server load, and a pleasantly fluid user experience

 + Creating a Service
     1. Define an service interface that extends RemoteService with methods
     2. Implement the service by extending RemoteServiceServlet and
        implementing the business methods in the service
     3. Define an asynchronous interface for the service to be called by the
        client-side

 + GWT RPC makes it easy for the client and server to pass Java
   objects back and forth over HTTP




32
                        VeriSign Proprietary and Confidential Information
RPC (Contd.)
  package com.example.foo.client;
  import com.google.gwt.user.client.rpc.RemoteService;
  public interface MyService extends RemoteService {
       public String myMethod(String s);
  }

  package com.example.foo.server;
  import com.google.gwt.user.server.rpc.RemoteServiceServlet;
  import com.example.client.MyService;
  public class MyServiceImpl extends RemoteServiceServlet implements MyService{
       public String myMethod(String s) {
           // Do something interesting with 's' here on the server.
           return s;
       }
  }

  package com.example.foo.client;
  interface MyServiceAsync {
       public void myMethod(String s, AsyncCallback<String> callback);
33 }
                             VeriSign Proprietary and Confidential Information
RPC (Contd.)
 + GWT RPC Plumbing




34
                    VeriSign Proprietary and Confidential Information
RPC (Contd.)
 + Asynchronously making the call involves the following steps
     //(1) Instantiate the service
     MyEmailServiceAsync myService = (MyService) GWT.create(MyService.class);


     //(2) Create an asynchronous callback to handle the result.
     AsyncCallback callback = new AsyncCallback() {
          public void onSuccess(Object result) {
              // do some UI stuff to show success
          }
          public void onFailure(Throwable caught) {
              // do some UI stuff to show failure
          }
     };


     // (3) Make the call.
     myService.mymethod(“abc”);


35
                                VeriSign Proprietary and Confidential Information
Image Bundle
 + Images in AJAX and Web applications
      ▪   Typically applications use a lot of images
      ▪   Each image is a separate file
      ▪   Browser fetches each separately

 + Studies have shown the following
      ▪   Large overhead:
           – Web applications have icons which are typically smaller than size of the
             request
           – Hence most of the traffic is overhead and very little of it actual content
      ▪   Useless freshness checks :
           – Even when the images have been cached by the client, a 304 (quot;Not Modifiedquot;)
             request is still sent to check and see if the image has change
           – Since images change infrequently, these freshness checks are also wasteful
      ▪   Blocking HTTP connections :
           – HTTP 1.1 requires browsers to limit the number of outgoing HTTP
             connections to two per domain/port
           – A multitude of image requests will tie up the browser's available connections,
             thus preventing real RPC requests that do the real work
36
                            VeriSign Proprietary and Confidential Information
Image Bundle (Contd.)
 + GWT solves performance problems by introducing a construct called
   Image Bundle


 + GWT Image Bundle bundles a bunch of image files into a single large
   file and manages as a single Java Object


 + Since filename is based on the hash of the file's contents, the
   filename will change only if the composite image is changed
      ▪   Hence, it is safe for clients to cache the composite image permanently,
          which avoids the unnecessary freshness checks for unchanged images
      ▪   To make this work, the server configuration needs to specify that
          composite images never expire.




37
                          VeriSign Proprietary and Confidential Information
Image Bundle (Contd.)
     + To define an image bundle, the developer needs to extend the
       ImageBundle interface
        ▪   The ImageBundle interface is a marker interface
        ▪   The derived interface can have zero or more methods, where each
            method must have the following characteristics
             – The method takes no parameters
             – The method has a a return type of AbstractImagePrototype
             – The method may have an optional gwt.resource metadata tag which
               specifies the name of the image file in the module's classpath

     + If the gwt.resource metadata tag is not specified, then the following
       assumptions are made
        ▪   The image filename is assumed to match the method name
        ▪   The extension is assumed to be either .png, .gif, or .jpg
        ▪   The file is assumed to be in the same package as the derived interface




38
                           VeriSign Proprietary and Confidential Information
Image Bundle (Contd.)
     public interface WordProcessorImageBundle extends ImageBundle {
       /**
        * Would match file 'new_file_icon.png', 'new_file_icon.gif', or
        * 'new_file_icon.png' located in the same package as this type.
        */
       public AbstractImagePrototype new_file_icon();

         /**
          * Would match the file 'open_file_icon.gif' located in the same
          * package as this type.
          * @gwt.resource open_file_icon.gif
          */
         public AbstractImagePrototype openFileIcon();

         /**
          * Would match the file 'savefile.gif' located in the package
          * 'com.mycompany.mygwtapp.icons', provided that this package is
         * part of the module's classpath.
          * @gwt.resource com/mycompany/mygwtapp/icons/savefile.gif
          */
         public AbstractImagePrototype saveFileIcon();
39   }
                          VeriSign Proprietary and Confidential Information
Image Bundle (Contd.)
 + Using Image bundle in the application
      public void useImageBundle() {
        WordProcessorImageBundle wpImageBundle =
         (WordProcessorImageBundle)
          GWT.create(WordProcessorImageBundle.class);
        HorizontalPanel tbPanel = new HorizontalPanel();
        tbPanel.add(wpImageBundle.new_file_icon().createImage());
        tbPanel.add(wpImageBundle.openFileIcon().createImage());
        tbPanel.add(wpImageBundle.saveFileIcon().createImage());
      }

 + Image bundles are immutable, so you can keep a reference to a singleton
   instance of an image bundle instead of creating a new instance every time
   the image bundle is needed




40
                      VeriSign Proprietary and Confidential Information
History
 + Ajax apps sometimes fail to meet user's expectations because they
   do not interact with the browser in the same way as static web pages
      ▪   Back button, forward button, bookmarking

 + The basic premise is to keep track of the application's quot;internal statequot;
   in the url fragment identifier
 + For each page that is to be navigable in the history, the application
   should generate a unique history token
 + For example, a history token named quot;page1quot; would be encoded in a
   URL as follows
      ▪   http://www.example.com/com.example.gwt.HistoryExample/
          HistoryExample.html#page1




41
                         VeriSign Proprietary and Confidential Information
History (Contd.)
 + When the application wants to push a placeholder onto the browser's
   history stack, it simply invokes History.newItem(token)
 +    When the user uses the back button, a callback will be passed to any
     object that was added as a listener to History.addHistoryListener()
      ▪   It is up to the app to restore the state according to the value of the token
 + To use GWT History support, you must first embed an iframe into your
   host HTML page
      <iframe src=quot;javascript:''quot; id=quot;__gwt_historyFramequot;
                     style=quot;width:0;height:0;border:0quot;></iframe>

 + When the onHistoryChanged() method is invoked, your application must
   handle two cases:
      ▪   The application was just started and was passed a history token.
      ▪   The application is already running and was passed a history token.


42
                           VeriSign Proprietary and Confidential Information
Internationalization and Configuration
 + GWT provides several techniques that can aid in Internationalization
   and configuration of your AJAX application
 + GWT provides 2 mechanisms
      ▪   Static String inclusion at compile time
           – Accomplished by GWT Constants interface which has pure messages
           – Accomplished by GWT Messages interface which allows parameterization
      ▪   Dynamic String inclusion at run time
           – Accomplished by GWT Dictionary class

 + Static Inclusion
           public interface MySettings extends Constants {
               String welcomeMessage();
               String logoImage();
               }
           public interface MySettings extends Messages {
               String welcomeMessage(String fname, String lname);
               String logoImage();
           }
43
                          VeriSign Proprietary and Confidential Information
Internationalization and Configuration (Contd.)
 + In the static approach, you define a default properties file of the format
   Filename.properties where Filename is the static property interface
   name such as MySettings.properties
 + For locale specific, you can also specific FileName_xx_YY.properties
   file where xx would be ISO Language code and YY ISO country code
 + Referencing constants from a resource file
      ▪   MySettings mySettings =(MySettings)GWT.create(MySettings.class);
      ▪   Label newLabel = new Label(Constants.labelText());

 + Static initialization are advantageous because
      ▪   Properties are statically included in compiled JavaScript, hence the
          performance is really good, same as hard coded string
      ▪   Compiler only includes properties that are refernces

 + Modules that use this interface should inherit com.google.gwt.i18n.I18N.
           <inherits name=quot;com.google.gwt.i18n.I18Nquot;/>


44
                          VeriSign Proprietary and Confidential Information
Internationalization and Configuration (Contd.)
 + Dynamic String Inclusion for Internationalization
      ▪   Allows existing i18n apps to be quickly incorporated into GWT applications
      ▪   Helpful if existing apps used JavaScript associate array objects for i18n
           var userInterfaceEN = {                                     var userInterfaceSV {
               hello: Hello,                                               hello: Hejsan,
               yes: Yes,                                                   yes: Ja,
               no: No                                                      no: Nej
           }                                                           }

 + Referencing constants from a resource file
      Disctionary uiText = Dictionary.getDictionary(“userInterfaceSV”);
      uiText.get(hello);

 + Advantage of Dynamic String initialization
      ▪   You can quickly incorporate existing i18n approach into the application

 + Disadvantage
      ▪   GWT provides no help whether constants you are referring to exist
      ▪   Compiler cannot perform any optimization
45
                          VeriSign Proprietary and Confidential Information
JavaScript Native Interface
 + GWT code is written in Java which gets translated into JavaScript, but
   sometimes there is a need to make JavaScript calls
      ▪   May need to call browser’s API for which no GWT equivalent exists
      ▪   May want to use some super-cool JavaScript lib

 + JavaScript Native Interface lets you execute JavaScript from Java as
   well as execute Java from JavaScript
 + Made possible because of the GWT compiler which can merge native
   JavaScript code with the JavaScript code generated from Java
 + Calling JavaScript from java
      public native int addTwoNumbers(int x, int y) {
      /*-{
             var result result = x+ y;return result;
      }-*/;




46
                         VeriSign Proprietary and Confidential Information
JavaScript Native Interface (Contd.)
 + Calling JavaScript from java

      public static native void alert(String msg) /*-{
        $wnd.alert(msg);
      }-*/

      public static native int badExample() /*-{
            throw(quot;Not A Number“);
      }-*/;

      public void onClick () {
            try {
               int myValue = badExample();
               GWT.log(quot;Got value quot; + myValue, null);
            } catch (Exception e) {
               GWT.log(quot;JSNI method badExample() threw an exception:quot;, e);
            }
         }




47
                       VeriSign Proprietary and Confidential Information
JavaScript Native Interface (Contd.)
 + Accessing Java from JavaScript
      ▪   [instance-expr.]@class-name::[field-name|method-name{}]
      ▪ instance-expr could be this or blank for static
      package mypackage;
      public MyUtilityClass {
          public static int calcLoanInterest(int amt, float intRate,
                                                     int term) { ... }
          public static native void exportStaticMethod() /*-{
             $wnd.computeLoanInterest =
                @mypackage.MyUtilityClass::calcLoanInterest(IFI);
          }-*/;
      }

 + Writing JSNI methods is powerful idea, but should be used sparingly
      ▪    because writing bulletproof JavaScript code is tricky
      ▪   JSNI code is potentially less portable across browsers
      ▪   Less amenable to Java tools
          Harder for the compiler to optimize
48
                          VeriSign Proprietary and Confidential Information
Packaging and Deploying a GWT Application
 + Output of the GWT compiler is purely static content
 + All one has to do is copy the GET generated content files from
   www/<package>.<modulename> into WAR file folder

 + GWT generated files can be put anywhere in the war file as long as it
   is URL accessible


 + But special steps have to be taken if the application uses GWT RPC
      ▪   Copy the gwt-servlet.jar from the GWT distribution to the WEB-
          INF/lib folder
      ▪   Compile all server side classes which are classes under server and copy
          them into WEB-INF/classes folder




49
                         VeriSign Proprietary and Confidential Information
JavaScript Obfuscation and Minimization
     + By default, GWT obfuscates the JavaScript it produces
     + Obfuscation done by the compiler partly
        ▪ To protect the intellectual property of the application you develop
        ▪ To reduce the size of the generated JavaScript files, thus making them faster to
          download and parse

     + If you prefer not to have GWT obfuscate its output, then you can use
       the quot;-stylequot; flag on the GWT Compile
        ▪ -style OBFUSCATED (small, efficient, and fast) – default style
        ▪ -style PRETTY (Human readable output)
        ▪ -style DETAILED (Similar to PRETTY with even more details – verbose
            variable names etc.)
     + If you are curious about what GWT's generated JavaScript is doing,
       then you can use quot;-style PRETTY“
     + On If you are debugging GWT's output, then quot;-style DETAILEDquot; might
       be helpful


50
                           VeriSign Proprietary and Confidential Information
GWT and JUnit Integration
 + Best practice in software engineering is to write automated tests
 + JUnit is best of breed Java Test Framework
 + GWT has integrated with JUnit
 + In order to write a new Test case, yo write a class that inherits from
   GWTTestCase which extends JUnit’s TestCase
 + You also need to implement one methods called
   “getModuleName()” at a minimum and then any number of test
   methods




51
                       VeriSign Proprietary and Confidential Information
Agenda

     + RIA Technologies, Frameworks and GWT
     + GWT Quickstart
     + GWT Architecture
     + Key GWT Features
     + Summary
     + Q&A




52
                        VeriSign Proprietary and Confidential Information
Summary
     + Paradigm shift in AJAX web development
     + Turn AJAX development into software engineering
     + Ph.D. in browser quirks is no longer a hiring pre requisite
     + Reusable UI components
     + Ease of development, debugging and maintenance
     + High performant
     + Developed, Backed by Google!




53
                         VeriSign Proprietary and Confidential Information
Agenda

     + RIA Technologies, Frameworks and GWT
     + GWT Quickstart
     + GWT Architecture
     + Key GWT Features
     + Summary
     + Q&A




54
                        VeriSign Proprietary and Confidential Information
Questions + Answers




55
                 VeriSign Proprietary and Confidential Information
Thank You




            Karthik Shyamsunder

Más contenido relacionado

La actualidad más candente

GWT Introduction for Eclipse Day
GWT Introduction for Eclipse Day GWT Introduction for Eclipse Day
GWT Introduction for Eclipse Day DNG Consulting
 
Reactjs Introduction - Virtual DOM
Reactjs Introduction - Virtual DOMReactjs Introduction - Virtual DOM
Reactjs Introduction - Virtual DOMTamir Azrab
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicCristiano Costantini
 
Intro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin ElementsIntro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin ElementsManuel Carrasco Moñino
 
Present and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectivePresent and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectiveManuel Carrasco Moñino
 
In defense of GWT-RPC By Colin Alworth
In defense of GWT-RPC By Colin AlworthIn defense of GWT-RPC By Colin Alworth
In defense of GWT-RPC By Colin AlworthGWTcon
 
Gwt.Create Keynote San Francisco
Gwt.Create Keynote San FranciscoGwt.Create Keynote San Francisco
Gwt.Create Keynote San FranciscoRay Cromwell
 
Headless Drupal: A modern approach to (micro)services and APIs
Headless Drupal: A modern approach to (micro)services and APIsHeadless Drupal: A modern approach to (micro)services and APIs
Headless Drupal: A modern approach to (micro)services and APIssparkfabrik
 
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)Igalia
 
GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011Manuel Carrasco Moñino
 
Gerrit JavaScript Plugins
Gerrit JavaScript PluginsGerrit JavaScript Plugins
Gerrit JavaScript PluginsDariusz Łuksza
 
WPE WebKit for Android
WPE WebKit for AndroidWPE WebKit for Android
WPE WebKit for AndroidIgalia
 

La actualidad más candente (20)

GWT and PWA
GWT and PWAGWT and PWA
GWT and PWA
 
GWT Introduction for Eclipse Day
GWT Introduction for Eclipse Day GWT Introduction for Eclipse Day
GWT Introduction for Eclipse Day
 
Reactjs Introduction - Virtual DOM
Reactjs Introduction - Virtual DOMReactjs Introduction - Virtual DOM
Reactjs Introduction - Virtual DOM
 
jQuery plugin & testing with Jasmine
jQuery plugin & testing with JasminejQuery plugin & testing with Jasmine
jQuery plugin & testing with Jasmine
 
CRUD with Polymer 2.0
CRUD with Polymer 2.0CRUD with Polymer 2.0
CRUD with Polymer 2.0
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 Panic
 
Intro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin ElementsIntro to Web Components, Polymer & Vaadin Elements
Intro to Web Components, Polymer & Vaadin Elements
 
React Django Presentation
React Django PresentationReact Django Presentation
React Django Presentation
 
Rock GWT UI's with Polymer Elements
Rock GWT UI's with Polymer ElementsRock GWT UI's with Polymer Elements
Rock GWT UI's with Polymer Elements
 
Present and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectivePresent and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspective
 
In defense of GWT-RPC By Colin Alworth
In defense of GWT-RPC By Colin AlworthIn defense of GWT-RPC By Colin Alworth
In defense of GWT-RPC By Colin Alworth
 
Gwt.Create Keynote San Francisco
Gwt.Create Keynote San FranciscoGwt.Create Keynote San Francisco
Gwt.Create Keynote San Francisco
 
Headless Drupal: A modern approach to (micro)services and APIs
Headless Drupal: A modern approach to (micro)services and APIsHeadless Drupal: A modern approach to (micro)services and APIs
Headless Drupal: A modern approach to (micro)services and APIs
 
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
 
GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011
 
Gerrit JavaScript Plugins
Gerrit JavaScript PluginsGerrit JavaScript Plugins
Gerrit JavaScript Plugins
 
Gwt session
Gwt sessionGwt session
Gwt session
 
Gradle presentation
Gradle presentationGradle presentation
Gradle presentation
 
Introduction of React.js
Introduction of React.jsIntroduction of React.js
Introduction of React.js
 
WPE WebKit for Android
WPE WebKit for AndroidWPE WebKit for Android
WPE WebKit for Android
 

Destacado

Web accessibility from a software engineering perspective: how RIAs and the m...
Web accessibility from a software engineering perspective: how RIAs and the m...Web accessibility from a software engineering perspective: how RIAs and the m...
Web accessibility from a software engineering perspective: how RIAs and the m...AEGIS-ACCESSIBLE Projects
 
Web 2 0 Ppt
Web 2 0 PptWeb 2 0 Ppt
Web 2 0 Pptrsyokesh
 
GWT architecture best practices and lessons learned
GWT architecture best practices and lessons learnedGWT architecture best practices and lessons learned
GWT architecture best practices and lessons learnedpgt technology scouting GmbH
 

Destacado (6)

Presentación FINAL
Presentación FINALPresentación FINAL
Presentación FINAL
 
RIA And SOA
RIA And SOARIA And SOA
RIA And SOA
 
Web accessibility from a software engineering perspective: how RIAs and the m...
Web accessibility from a software engineering perspective: how RIAs and the m...Web accessibility from a software engineering perspective: how RIAs and the m...
Web accessibility from a software engineering perspective: how RIAs and the m...
 
Web 2 0 Ppt
Web 2 0 PptWeb 2 0 Ppt
Web 2 0 Ppt
 
GWT architecture best practices and lessons learned
GWT architecture best practices and lessons learnedGWT architecture best practices and lessons learned
GWT architecture best practices and lessons learned
 
Gwt ppt
Gwt pptGwt ppt
Gwt ppt
 

Similar a Building Rich Internet Applications Using Google Web Toolkit

GWT + Gears : The browser is the platform
GWT + Gears : The browser is the platformGWT + Gears : The browser is the platform
GWT + Gears : The browser is the platformDidier Girard
 
Javascript Essentials - Cisco Live Barcelona 2019
Javascript Essentials - Cisco Live Barcelona 2019Javascript Essentials - Cisco Live Barcelona 2019
Javascript Essentials - Cisco Live Barcelona 2019Cisco DevNet
 
Netbeans65 Osum Slides
Netbeans65 Osum SlidesNetbeans65 Osum Slides
Netbeans65 Osum SlidesAbhishek Gupta
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Ryan Cuprak
 
JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014Ryan Cuprak
 
S60 3rd FP2 Widgets
S60 3rd FP2 WidgetsS60 3rd FP2 Widgets
S60 3rd FP2 Widgetsromek
 
Net Beans61 Ide
Net Beans61 IdeNet Beans61 Ide
Net Beans61 Idesatyajit_t
 
Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web ToolkitDidier Girard
 
JCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptxJCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptxGrace Jansen
 
Java @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPJava @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPIlan Salviano
 
WebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureWebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureFrank Greco
 
Evolving Mobile Architectures
Evolving Mobile ArchitecturesEvolving Mobile Architectures
Evolving Mobile Architecturessgleadow
 
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and Vaadin
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and VaadinSimple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and Vaadin
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and VaadinJian Wu
 
Devfest09 Cschalk Gwt
Devfest09 Cschalk GwtDevfest09 Cschalk Gwt
Devfest09 Cschalk GwtChris Schalk
 
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891Cisco DevNet
 
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13Fred Sauer
 

Similar a Building Rich Internet Applications Using Google Web Toolkit (20)

Glass Fish Portfolio Web Server Cvr
Glass Fish Portfolio Web Server CvrGlass Fish Portfolio Web Server Cvr
Glass Fish Portfolio Web Server Cvr
 
GWT + Gears : The browser is the platform
GWT + Gears : The browser is the platformGWT + Gears : The browser is the platform
GWT + Gears : The browser is the platform
 
Web assembly with PWA
Web assembly with PWA Web assembly with PWA
Web assembly with PWA
 
Javascript Essentials - Cisco Live Barcelona 2019
Javascript Essentials - Cisco Live Barcelona 2019Javascript Essentials - Cisco Live Barcelona 2019
Javascript Essentials - Cisco Live Barcelona 2019
 
Node.js Tools Ecosystem
Node.js Tools EcosystemNode.js Tools Ecosystem
Node.js Tools Ecosystem
 
Netbeans65 Osum Slides
Netbeans65 Osum SlidesNetbeans65 Osum Slides
Netbeans65 Osum Slides
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
 
JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014
 
S60 3rd FP2 Widgets
S60 3rd FP2 WidgetsS60 3rd FP2 Widgets
S60 3rd FP2 Widgets
 
Net Beans61 Ide
Net Beans61 IdeNet Beans61 Ide
Net Beans61 Ide
 
Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web Toolkit
 
JCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptxJCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptx
 
Java @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SPJava @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SP
 
Ajax
Ajax Ajax
Ajax
 
WebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the FutureWebSocket Perspectives and Vision for the Future
WebSocket Perspectives and Vision for the Future
 
Evolving Mobile Architectures
Evolving Mobile ArchitecturesEvolving Mobile Architectures
Evolving Mobile Architectures
 
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and Vaadin
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and VaadinSimple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and Vaadin
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and Vaadin
 
Devfest09 Cschalk Gwt
Devfest09 Cschalk GwtDevfest09 Cschalk Gwt
Devfest09 Cschalk Gwt
 
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
 
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
 

Más de rajivmordani

Web 2 0 Data Visualization With Jsf
Web 2 0 Data Visualization With JsfWeb 2 0 Data Visualization With Jsf
Web 2 0 Data Visualization With Jsfrajivmordani
 
X Aware Ajax World V1
X Aware Ajax World V1X Aware Ajax World V1
X Aware Ajax World V1rajivmordani
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Tripit Ajaxworld V5
Tripit Ajaxworld V5Tripit Ajaxworld V5
Tripit Ajaxworld V5rajivmordani
 
Turbo Enterprise Web 2.0 Ajax World 20081
Turbo Enterprise Web 2.0 Ajax World 20081Turbo Enterprise Web 2.0 Ajax World 20081
Turbo Enterprise Web 2.0 Ajax World 20081rajivmordani
 
Sue Googe Spice Up Ux
Sue Googe Spice Up UxSue Googe Spice Up Ux
Sue Googe Spice Up Uxrajivmordani
 
Social Networking Intranet
Social Networking IntranetSocial Networking Intranet
Social Networking Intranetrajivmordani
 
Practical Thin Server Architecture With Dojo Peter Svensson
Practical Thin Server Architecture With Dojo Peter SvenssonPractical Thin Server Architecture With Dojo Peter Svensson
Practical Thin Server Architecture With Dojo Peter Svenssonrajivmordani
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascriptrajivmordani
 
Slow Cool 20081009 Final
Slow Cool 20081009 FinalSlow Cool 20081009 Final
Slow Cool 20081009 Finalrajivmordani
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax Wrajivmordani
 
I Phone Dev Summit Prezo Guy Naor Final
I Phone Dev Summit Prezo Guy Naor FinalI Phone Dev Summit Prezo Guy Naor Final
I Phone Dev Summit Prezo Guy Naor Finalrajivmordani
 
Netapp Michael Galpin
Netapp Michael GalpinNetapp Michael Galpin
Netapp Michael Galpinrajivmordani
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008rajivmordani
 
Mike Grushin Developing Ugc Sites That Scale
Mike Grushin    Developing Ugc Sites That ScaleMike Grushin    Developing Ugc Sites That Scale
Mike Grushin Developing Ugc Sites That Scalerajivmordani
 
Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1rajivmordani
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockfordrajivmordani
 

Más de rajivmordani (20)

Web 2 0 Data Visualization With Jsf
Web 2 0 Data Visualization With JsfWeb 2 0 Data Visualization With Jsf
Web 2 0 Data Visualization With Jsf
 
X Aware Ajax World V1
X Aware Ajax World V1X Aware Ajax World V1
X Aware Ajax World V1
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Tripit Ajaxworld V5
Tripit Ajaxworld V5Tripit Ajaxworld V5
Tripit Ajaxworld V5
 
Turbo Enterprise Web 2.0 Ajax World 20081
Turbo Enterprise Web 2.0 Ajax World 20081Turbo Enterprise Web 2.0 Ajax World 20081
Turbo Enterprise Web 2.0 Ajax World 20081
 
Sue Googe Spice Up Ux
Sue Googe Spice Up UxSue Googe Spice Up Ux
Sue Googe Spice Up Ux
 
Social Networking Intranet
Social Networking IntranetSocial Networking Intranet
Social Networking Intranet
 
Ssjs Presentation
Ssjs PresentationSsjs Presentation
Ssjs Presentation
 
Jsf Ajax
Jsf AjaxJsf Ajax
Jsf Ajax
 
Practical Thin Server Architecture With Dojo Peter Svensson
Practical Thin Server Architecture With Dojo Peter SvenssonPractical Thin Server Architecture With Dojo Peter Svensson
Practical Thin Server Architecture With Dojo Peter Svensson
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
 
Ria Enterprise
Ria EnterpriseRia Enterprise
Ria Enterprise
 
Slow Cool 20081009 Final
Slow Cool 20081009 FinalSlow Cool 20081009 Final
Slow Cool 20081009 Final
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
 
I Phone Dev Summit Prezo Guy Naor Final
I Phone Dev Summit Prezo Guy Naor FinalI Phone Dev Summit Prezo Guy Naor Final
I Phone Dev Summit Prezo Guy Naor Final
 
Netapp Michael Galpin
Netapp Michael GalpinNetapp Michael Galpin
Netapp Michael Galpin
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008
 
Mike Grushin Developing Ugc Sites That Scale
Mike Grushin    Developing Ugc Sites That ScaleMike Grushin    Developing Ugc Sites That Scale
Mike Grushin Developing Ugc Sites That Scale
 
Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1Java Fx Ajaxworld Rags V1
Java Fx Ajaxworld Rags V1
 
Good Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas CrockfordGood Parts of JavaScript Douglas Crockford
Good Parts of JavaScript Douglas Crockford
 

Último

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

Building Rich Internet Applications Using Google Web Toolkit

  • 1. Building Rich Internet Applications Using Google Web Toolkit (GWT) Karthik Shyamsunder October 2008 Karthik Shyamsunder
  • 2. Who am I? + Karthik Shyamsunder ▪ Principal Engineer, VeriSign Inc. ▪ Application Architect for the VeriSign Naming Division ▪ Adjunct Faculty at Johns Hopkins University ▪ Speak at conferences on Architecture, Security, Performance, Distributed Computing, Language/Design 2 VeriSign Proprietary and Confidential Information
  • 3. Overall Goal of this Session 1. Introduce you to the GWT framework and application development 2. Discuss key features in GWT that will allow you to build no compromise AJAX applications 3 VeriSign Proprietary and Confidential Information
  • 4. Agenda + RIA Technologies, Frameworks and GWT + GWT Quickstart + GWT Architecture + Key GWT Features + Summary + Q&A 4 VeriSign Proprietary and Confidential Information
  • 5. Agenda + RIA Technologies, Frameworks and GWT + GWT Quickstart + GWT Architecture + Key GWT Features + Summary + Q&A 5 VeriSign Proprietary and Confidential Information
  • 6. What are Rich Internet Applications? + Web applications that have the features and Backend functionality of traditional desktop applications Processes + Typically do the following: Server Logic ▪ run in a web browser, or do not require software installation ▪ run locally in a secure environment called a Server sandbox + Typically transfer the processing necessary for the user interface to the web client but keep the bulk of the data back on the application server (Sandbox + Make asynchronous/synchronous calls to the Client Engine) backend based on user actions/events + “Thick Client” Application VeriSign Proprietary and Confidential Information
  • 7. Technologies for Building RIAs + Several technologies available for building Rich Internet Applications Backend Processes + Key Technologies for building RIAs Server Logic ▪ Adobe Flex ▪ Microsoft Silverlight Server ▪ Java Applets/WebStart ▪ AJAX + Other Technologies and Frameworks for (Sandbox building RIAs Client Engine) ▪ Java FX ▪ Open Laszlo VeriSign Proprietary and Confidential Information
  • 8. Building RIAs using Java EE and AJAX We can classify building applications in AJAX into 2 : 1. Client Side AJAX Development – Presentation using HTML/JSP pages using client side frameworks such as Scriptaculous, JQuery, Dojo client side components – Presentation logic using JavaScript – Server Side development using traditional Java EE Servlets/Services exposing backend services as REST, XML RPC Web Services – Call backend business logic in the background using the JavaScript language and XMLHttpRequest object built into the browser 2. Server Side AJAX Development – Presentation using component frameworks JSTL tag libraries such as JBoss RichFaces, Icesoft Icefaces built on on top of JSF – Presentation logic done as event handlers in JSF component model – Call to backend business logic using JSF event Model VeriSign Proprietary and Confidential Information
  • 9. Challenges with typical AJAX development + JavaScript ▪ Not a strongly typed language ▪ Static Type checking? ▪ Code completion? ▪ Runtime-only bugs + Browser compatibilities = “if/else soup” ▪ OK, we have frameworks ▪ Too many frameworks! + Juggling multiple languages (JavaScript, JSP tags, Java, XML, HTML etc.) ▪ Less modularization ▪ Maintenance nightmare + Poor debugging ▪ Window.alert(), Firebug ▪ But what about end to end + Back button + Limited IDE support 9 VeriSign Proprietary and Confidential Information
  • 10. Introducing Google Web Toolkit 10 VeriSign Proprietary and Confidential Information
  • 11. Introducing GWT + What is GWT? ▪ GWT is an open source Java development framework ▪ Provides set of tools for building AJAX apps in the Java language + What makes GWT interesting? ▪ Write, run, test, and debug everything in JAVA! + GWT ≠ applets ▪ GWT converts your Java source into equivalent JavaScript + Is GWT a compiler? ▪ GWT has a compiler, but it has lot more to offer… 11 VeriSign Proprietary and Confidential Information
  • 12. Why Use Java Language for AJAX Development? + Static type checking in the Java language boosts productivity while reducing errors + Common JavaScript errors (typos, type mismatches) are easily caught at compile time rather than by users at runtime + Code prompting/completion is widely available + Automated Java refactoring is pretty snazzy these days + Java-based OO designs are easier to communicate and understand, thus making your AJAX code base more comprehensible with less documentation. 12 VeriSign Proprietary and Confidential Information
  • 13. Advantages of GWT + No need to learn/use JavaScript language ▪ Leverage Java programming knowledge you already have + No need to handle browser incompatibilities and quirks ▪ GWT handles them for you + No need to learn/use DOM APIs ▪ Use Java APIs + No need to handle forward/backward buttons browser-history ▪ GWT handles it for you + No need to build commonly used Widgets ▪ Most of them come with GWT + Can send complex Java types to/from the server ▪ Data gets serialized across network 13 VeriSign Proprietary and Confidential Information
  • 14. Advantages of GWT + Leverage various tools of Java programming language for writing/debugging/testing ▪ For example, NetBeans or Eclipse + Internationalization ▪ GWT includes a flexible set of tools to help you internationalize your applications and libraries ▪ GWT internationalization support provides a variety of techniques + JUnit integration ▪ GWT's direct integration with JUnit lets you unit test both in a debugger and in a browser and you can even unit test asynchronous RPCs + Support by major company ▪ From the company that popularized Ajax in the first place ▪ Company won't go away like perhaps with AjaxTags 14 VeriSign Proprietary and Confidential Information
  • 15. Disadvantages of GWT + Only for Java developers ▪ Most Ajax environments do JavaScript on the client and have a choice for the server. GWT is based entirely around Java. + Big learning curve ▪ Java developers can deploy with AjaxTags in just a few minutes, whereas it takes much longer to get anything running with GWT. + Cumbersome deployment ▪ Clumsy and poorly documented process to deploy on a regular Java- based Web server. + Nonstandard approach to integrate JavaScript ▪ You never put direct JavaScript in your HTML. Instead, you use JSNI to wrap JavaScript in Java. – Very powerful in the long run, but hard to get used to at first. + Unusual approach ▪ Fundamentally different strategy than all other Ajax environments makes evaluation and management buyoff harder 15 VeriSign Proprietary and Confidential Information
  • 16. Agenda + RIA Technologies, Frameworks and GWT + GWT Quickstart + GWT Architecture + Key GWT Features + Summary + Q&A 16 VeriSign Proprietary and Confidential Information
  • 17. Downloading and Installing GWT + Official Site for GWT is http://code.google.com/webtoolkit/ + Downloading GWT ▪ You can download the latest version of software from http://code.google.com/webtoolkit/download.html ▪ Licensed under Apache 2.0 open source license scheme ▪ Latest version of the software is GWT 1.5 + Installing GWT ▪ Extract the ZIP file into wherever you want to install the toolkit ▪ That’s it! + Setting up the development environment ▪ Add {INSTALL-DIR}gwt-windows-1.5.2 to your PATH ▪ This is so that the many of the toolkit commands are available + Since GWT is java based tool ensure that you have JDK 1.5 or above and JAVA_HOME is set 17 VeriSign Proprietary and Confidential Information
  • 18. Application Development Steps + Create an Eclipse application ▪ Use projectCreator and applicationCreator scripts ▪ You can make non-Eclipse projects also, but the tutorial examples assume Eclipse. I use MyEclipse, but it is similar in both versions. + Edit auto-generated HTML file ▪ Called AppName.html – Under src/package.../public folder in Eclipse ▪ Give ids to regions where controls will be placed + Edit auto-generated Java application class ▪ Class: package...client.AppName – Under src folder in Eclipse ▪ Method: onModuleLoad ▪ Create controls and give them event handlers ▪ Insert controls into HTML page – RootPanel.get(quot;htmlIDquot;).add(control); 18 VeriSign Proprietary and Confidential Information
  • 19. Application Development Steps 1. Make sure PATH includes GWT install directory ▪ Or specify full path for scripts 2. Make a temporary directory for your project ▪ Directory name is arbitrary 3. Make a blank Eclipse project Names must match ▪ DOS> projectCreator –eclipse GwtTestProject 4. Make a starting-point application ▪ DOS> applicationCreator –eclipse GwtTestProject myPackage.client.GwtTestApplication Name of driver class that will be created. 5. Start Eclipse and import project Rightmost package name must be quot;clientquot;. ▪ File > Import > Existing Projects into Workspace – Browse to directory from (2) above and click quot;Finishquot; – If you specify quot;copy filesquot; (usual approach), then delete the temporary directory from (2) above 19 VeriSign Proprietary and Confidential Information
  • 20. Application Development Steps Starting-point HTML file. You will edit this extensively. When you make server-side code, register servlet in here. Client-side code must be in quot;clientquot; package. Server- side code can also import and call classes in this package (other than main app). All code in this package will eventually get translated into JavaScript. Starting point client-side code. You will edit this extensively. After you have finished testing and debugging, you can double-click this to generate www directory containing HTML and JavaScript that can run in a regular browser. But an easier way to build these files is to run in hosted mode and then click Compile/Browse (see later slides). Not needed if you run within an IDE. 20 VeriSign Proprietary and Confidential Information
  • 21. Agenda + RIA Technologies, Frameworks and GWT + GWT Quickstart + GWT Architecture + Key GWT Features + Summary + Q&A 21 VeriSign Proprietary and Confidential Information
  • 22. GWT Architecture 22 VeriSign Proprietary and Confidential Information
  • 23. Google Web Toolkit - Architecture Server Side Client Side .java .java Web/Application Server D E Java GWT P L HTTP/ Compiler Compiler O REST/ Y Web Services XML/ JSON/ (AJAX Runtime RPC Engine) .class .html .html .html . js VeriSign Proprietary and Confidential Information
  • 24. Running GWT Applications Hosted Mode ▪ Application is run as Java byte code within the JVM ▪ Developers spend most of their time in hosted mode to take advantage of Java's debugging facilities and other features + Web mode ▪ Application is run as pure JavaScript and HTML, compiled from your original Java source code with the GWT Java-to- JavaScript compiler ▪ You deploy this JavaScript and HTML to production, so end users sees web version of your app 24 VeriSign Proprietary and Confidential Information
  • 25. Agenda + RIA Technologies, Frameworks and GWT + GWT Quickstart + GWT Architecture + Key GWT Features + Summary + Q&A 25 VeriSign Proprietary and Confidential Information
  • 26. What browsers does GWT Support? + Officially as of mid 2008, GWT supports the following browsers: ▪ Firefox 1.0, 1.5, 2.0 and 3.0 ▪ Internet Explorer 6 and 7 ▪ Safari 2 and 3 ▪ Opera 9.0 26 VeriSign Proprietary and Confidential Information
  • 27. GWT Widgets and Layout 27 VeriSign Proprietary and Confidential Information
  • 28. UI components & Event Programming Model + Programming model similar UI frameworks such as Swing + Primary difference between Swing and GWT is here widgets are dynamically transformed to HTML rather than pixel-oriented graphics + Using widgets makes it much easier to quickly build interfaces that will work correctly on all browsers Button btnOk = new Button(“OK”); CheckBox married= new CheckBox(“Married”); + Events in GWT use the quot;listener interfacequot; model similar to other user interface frameworks (like Swing) btnOk.addClickListener(new MyClickListener()); + Possible to manipulate the browser's DOM directly using the DOM interface, but better to use Java classes from Widget library 28 VeriSign Proprietary and Confidential Information
  • 29. Style with CSS + Each widget class has an associated style name that binds it to a CSS rule ▪ For example GWT Button has a style called “gwt-Button” + A widget’s style name can be set using ▪ setStyleName(String) + Also possible to assign an id to a particular component to create a CSS rule that applies to just one component ▪ <div id=“my-button-id”/> + To set the id for a GWT widget, retrieve its DOM Element and then set the id attribute as follows ▪ Button b = new Button(); ▪ DOM.setElementAttribute(b.getElement(), quot;idquot;, quot;my-button-idquot;) + Allows you to reference a specific widget in a stylesheet as follows #my-button-id { font-size: 100%; } 29 VeriSign Proprietary and Confidential Information
  • 30. Style with CSS (Contd.) + Including Stylesheets in the HTML Host Page ▪ Stylesheets are placed in the module's public path ▪ Refer to them them by simply using a <link> tag in the page: <link rel=quot;stylesheetquot; href=quot;mystyles.cssquot; type=quot;text/cssquot;/> + GWT comes with 3 default visual themes that you can choose from ▪ Standard, Chrome, and Dark + By default new applications use standard theme + Other themes can be selected by adding inherits tag in the Main.gwt.xml file <inherits name='com.google.gwt.user.theme.standard.Standard'/> <inherits name=quot;com.google.gwt.user.theme.chrome.Chromequot;/> <inherits name=quot;com.google.gwt.user.theme.dark.Darkquot;/> 30 VeriSign Proprietary and Confidential Information
  • 31. Third Party Visual Builder - Instantiations + Instantiations, a software company in Portland Oregon, USA + Has a product called GWT Designer which is a powerful bi0directional WYSIWYG tool that may be worth looking into 31 VeriSign Proprietary and Confidential Information
  • 32. RPC + RPCs give you the opportunity to move all UI logic to the client, thus ▪ Geatly improving performance ▪ Reducing bandwidth ▪ Reducing web server load, and a pleasantly fluid user experience + Creating a Service 1. Define an service interface that extends RemoteService with methods 2. Implement the service by extending RemoteServiceServlet and implementing the business methods in the service 3. Define an asynchronous interface for the service to be called by the client-side + GWT RPC makes it easy for the client and server to pass Java objects back and forth over HTTP 32 VeriSign Proprietary and Confidential Information
  • 33. RPC (Contd.) package com.example.foo.client; import com.google.gwt.user.client.rpc.RemoteService; public interface MyService extends RemoteService { public String myMethod(String s); } package com.example.foo.server; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.example.client.MyService; public class MyServiceImpl extends RemoteServiceServlet implements MyService{ public String myMethod(String s) { // Do something interesting with 's' here on the server. return s; } } package com.example.foo.client; interface MyServiceAsync { public void myMethod(String s, AsyncCallback<String> callback); 33 } VeriSign Proprietary and Confidential Information
  • 34. RPC (Contd.) + GWT RPC Plumbing 34 VeriSign Proprietary and Confidential Information
  • 35. RPC (Contd.) + Asynchronously making the call involves the following steps //(1) Instantiate the service MyEmailServiceAsync myService = (MyService) GWT.create(MyService.class); //(2) Create an asynchronous callback to handle the result. AsyncCallback callback = new AsyncCallback() { public void onSuccess(Object result) { // do some UI stuff to show success } public void onFailure(Throwable caught) { // do some UI stuff to show failure } }; // (3) Make the call. myService.mymethod(“abc”); 35 VeriSign Proprietary and Confidential Information
  • 36. Image Bundle + Images in AJAX and Web applications ▪ Typically applications use a lot of images ▪ Each image is a separate file ▪ Browser fetches each separately + Studies have shown the following ▪ Large overhead: – Web applications have icons which are typically smaller than size of the request – Hence most of the traffic is overhead and very little of it actual content ▪ Useless freshness checks : – Even when the images have been cached by the client, a 304 (quot;Not Modifiedquot;) request is still sent to check and see if the image has change – Since images change infrequently, these freshness checks are also wasteful ▪ Blocking HTTP connections : – HTTP 1.1 requires browsers to limit the number of outgoing HTTP connections to two per domain/port – A multitude of image requests will tie up the browser's available connections, thus preventing real RPC requests that do the real work 36 VeriSign Proprietary and Confidential Information
  • 37. Image Bundle (Contd.) + GWT solves performance problems by introducing a construct called Image Bundle + GWT Image Bundle bundles a bunch of image files into a single large file and manages as a single Java Object + Since filename is based on the hash of the file's contents, the filename will change only if the composite image is changed ▪ Hence, it is safe for clients to cache the composite image permanently, which avoids the unnecessary freshness checks for unchanged images ▪ To make this work, the server configuration needs to specify that composite images never expire. 37 VeriSign Proprietary and Confidential Information
  • 38. Image Bundle (Contd.) + To define an image bundle, the developer needs to extend the ImageBundle interface ▪ The ImageBundle interface is a marker interface ▪ The derived interface can have zero or more methods, where each method must have the following characteristics – The method takes no parameters – The method has a a return type of AbstractImagePrototype – The method may have an optional gwt.resource metadata tag which specifies the name of the image file in the module's classpath + If the gwt.resource metadata tag is not specified, then the following assumptions are made ▪ The image filename is assumed to match the method name ▪ The extension is assumed to be either .png, .gif, or .jpg ▪ The file is assumed to be in the same package as the derived interface 38 VeriSign Proprietary and Confidential Information
  • 39. Image Bundle (Contd.) public interface WordProcessorImageBundle extends ImageBundle { /** * Would match file 'new_file_icon.png', 'new_file_icon.gif', or * 'new_file_icon.png' located in the same package as this type. */ public AbstractImagePrototype new_file_icon(); /** * Would match the file 'open_file_icon.gif' located in the same * package as this type. * @gwt.resource open_file_icon.gif */ public AbstractImagePrototype openFileIcon(); /** * Would match the file 'savefile.gif' located in the package * 'com.mycompany.mygwtapp.icons', provided that this package is * part of the module's classpath. * @gwt.resource com/mycompany/mygwtapp/icons/savefile.gif */ public AbstractImagePrototype saveFileIcon(); 39 } VeriSign Proprietary and Confidential Information
  • 40. Image Bundle (Contd.) + Using Image bundle in the application public void useImageBundle() { WordProcessorImageBundle wpImageBundle = (WordProcessorImageBundle) GWT.create(WordProcessorImageBundle.class); HorizontalPanel tbPanel = new HorizontalPanel(); tbPanel.add(wpImageBundle.new_file_icon().createImage()); tbPanel.add(wpImageBundle.openFileIcon().createImage()); tbPanel.add(wpImageBundle.saveFileIcon().createImage()); } + Image bundles are immutable, so you can keep a reference to a singleton instance of an image bundle instead of creating a new instance every time the image bundle is needed 40 VeriSign Proprietary and Confidential Information
  • 41. History + Ajax apps sometimes fail to meet user's expectations because they do not interact with the browser in the same way as static web pages ▪ Back button, forward button, bookmarking + The basic premise is to keep track of the application's quot;internal statequot; in the url fragment identifier + For each page that is to be navigable in the history, the application should generate a unique history token + For example, a history token named quot;page1quot; would be encoded in a URL as follows ▪ http://www.example.com/com.example.gwt.HistoryExample/ HistoryExample.html#page1 41 VeriSign Proprietary and Confidential Information
  • 42. History (Contd.) + When the application wants to push a placeholder onto the browser's history stack, it simply invokes History.newItem(token) + When the user uses the back button, a callback will be passed to any object that was added as a listener to History.addHistoryListener() ▪ It is up to the app to restore the state according to the value of the token + To use GWT History support, you must first embed an iframe into your host HTML page <iframe src=quot;javascript:''quot; id=quot;__gwt_historyFramequot; style=quot;width:0;height:0;border:0quot;></iframe> + When the onHistoryChanged() method is invoked, your application must handle two cases: ▪ The application was just started and was passed a history token. ▪ The application is already running and was passed a history token. 42 VeriSign Proprietary and Confidential Information
  • 43. Internationalization and Configuration + GWT provides several techniques that can aid in Internationalization and configuration of your AJAX application + GWT provides 2 mechanisms ▪ Static String inclusion at compile time – Accomplished by GWT Constants interface which has pure messages – Accomplished by GWT Messages interface which allows parameterization ▪ Dynamic String inclusion at run time – Accomplished by GWT Dictionary class + Static Inclusion public interface MySettings extends Constants { String welcomeMessage(); String logoImage(); } public interface MySettings extends Messages { String welcomeMessage(String fname, String lname); String logoImage(); } 43 VeriSign Proprietary and Confidential Information
  • 44. Internationalization and Configuration (Contd.) + In the static approach, you define a default properties file of the format Filename.properties where Filename is the static property interface name such as MySettings.properties + For locale specific, you can also specific FileName_xx_YY.properties file where xx would be ISO Language code and YY ISO country code + Referencing constants from a resource file ▪ MySettings mySettings =(MySettings)GWT.create(MySettings.class); ▪ Label newLabel = new Label(Constants.labelText()); + Static initialization are advantageous because ▪ Properties are statically included in compiled JavaScript, hence the performance is really good, same as hard coded string ▪ Compiler only includes properties that are refernces + Modules that use this interface should inherit com.google.gwt.i18n.I18N. <inherits name=quot;com.google.gwt.i18n.I18Nquot;/> 44 VeriSign Proprietary and Confidential Information
  • 45. Internationalization and Configuration (Contd.) + Dynamic String Inclusion for Internationalization ▪ Allows existing i18n apps to be quickly incorporated into GWT applications ▪ Helpful if existing apps used JavaScript associate array objects for i18n var userInterfaceEN = { var userInterfaceSV { hello: Hello, hello: Hejsan, yes: Yes, yes: Ja, no: No no: Nej } } + Referencing constants from a resource file Disctionary uiText = Dictionary.getDictionary(“userInterfaceSV”); uiText.get(hello); + Advantage of Dynamic String initialization ▪ You can quickly incorporate existing i18n approach into the application + Disadvantage ▪ GWT provides no help whether constants you are referring to exist ▪ Compiler cannot perform any optimization 45 VeriSign Proprietary and Confidential Information
  • 46. JavaScript Native Interface + GWT code is written in Java which gets translated into JavaScript, but sometimes there is a need to make JavaScript calls ▪ May need to call browser’s API for which no GWT equivalent exists ▪ May want to use some super-cool JavaScript lib + JavaScript Native Interface lets you execute JavaScript from Java as well as execute Java from JavaScript + Made possible because of the GWT compiler which can merge native JavaScript code with the JavaScript code generated from Java + Calling JavaScript from java public native int addTwoNumbers(int x, int y) { /*-{ var result result = x+ y;return result; }-*/; 46 VeriSign Proprietary and Confidential Information
  • 47. JavaScript Native Interface (Contd.) + Calling JavaScript from java public static native void alert(String msg) /*-{ $wnd.alert(msg); }-*/ public static native int badExample() /*-{ throw(quot;Not A Number“); }-*/; public void onClick () { try { int myValue = badExample(); GWT.log(quot;Got value quot; + myValue, null); } catch (Exception e) { GWT.log(quot;JSNI method badExample() threw an exception:quot;, e); } } 47 VeriSign Proprietary and Confidential Information
  • 48. JavaScript Native Interface (Contd.) + Accessing Java from JavaScript ▪ [instance-expr.]@class-name::[field-name|method-name{}] ▪ instance-expr could be this or blank for static package mypackage; public MyUtilityClass { public static int calcLoanInterest(int amt, float intRate, int term) { ... } public static native void exportStaticMethod() /*-{ $wnd.computeLoanInterest = @mypackage.MyUtilityClass::calcLoanInterest(IFI); }-*/; } + Writing JSNI methods is powerful idea, but should be used sparingly ▪ because writing bulletproof JavaScript code is tricky ▪ JSNI code is potentially less portable across browsers ▪ Less amenable to Java tools Harder for the compiler to optimize 48 VeriSign Proprietary and Confidential Information
  • 49. Packaging and Deploying a GWT Application + Output of the GWT compiler is purely static content + All one has to do is copy the GET generated content files from www/<package>.<modulename> into WAR file folder + GWT generated files can be put anywhere in the war file as long as it is URL accessible + But special steps have to be taken if the application uses GWT RPC ▪ Copy the gwt-servlet.jar from the GWT distribution to the WEB- INF/lib folder ▪ Compile all server side classes which are classes under server and copy them into WEB-INF/classes folder 49 VeriSign Proprietary and Confidential Information
  • 50. JavaScript Obfuscation and Minimization + By default, GWT obfuscates the JavaScript it produces + Obfuscation done by the compiler partly ▪ To protect the intellectual property of the application you develop ▪ To reduce the size of the generated JavaScript files, thus making them faster to download and parse + If you prefer not to have GWT obfuscate its output, then you can use the quot;-stylequot; flag on the GWT Compile ▪ -style OBFUSCATED (small, efficient, and fast) – default style ▪ -style PRETTY (Human readable output) ▪ -style DETAILED (Similar to PRETTY with even more details – verbose variable names etc.) + If you are curious about what GWT's generated JavaScript is doing, then you can use quot;-style PRETTY“ + On If you are debugging GWT's output, then quot;-style DETAILEDquot; might be helpful 50 VeriSign Proprietary and Confidential Information
  • 51. GWT and JUnit Integration + Best practice in software engineering is to write automated tests + JUnit is best of breed Java Test Framework + GWT has integrated with JUnit + In order to write a new Test case, yo write a class that inherits from GWTTestCase which extends JUnit’s TestCase + You also need to implement one methods called “getModuleName()” at a minimum and then any number of test methods 51 VeriSign Proprietary and Confidential Information
  • 52. Agenda + RIA Technologies, Frameworks and GWT + GWT Quickstart + GWT Architecture + Key GWT Features + Summary + Q&A 52 VeriSign Proprietary and Confidential Information
  • 53. Summary + Paradigm shift in AJAX web development + Turn AJAX development into software engineering + Ph.D. in browser quirks is no longer a hiring pre requisite + Reusable UI components + Ease of development, debugging and maintenance + High performant + Developed, Backed by Google! 53 VeriSign Proprietary and Confidential Information
  • 54. Agenda + RIA Technologies, Frameworks and GWT + GWT Quickstart + GWT Architecture + Key GWT Features + Summary + Q&A 54 VeriSign Proprietary and Confidential Information
  • 55. Questions + Answers 55 VeriSign Proprietary and Confidential Information
  • 56. Thank You Karthik Shyamsunder