SlideShare a Scribd company logo
Google Web Toolkit
Assoc.Prof. Dr.Thanachart Numnonda
 Asst.Prof. Thanisa Kruawaisayawan

        www.imcinstitute.com
             July 2012
Agenda
RIA and AJAX

What is Google Web Toolkit?

GWT Implementation

GWT Components

GWT RPC
RIA and AJAX?
Rich Internet Applications
Web applications that have the features and functionality of
  traditional desktop applications
Typically transfer the processing necessary for the user
  interface to the web client but keep the bulk of the data back o
  n the application server.
Make asynchronous/synchronous calls to thebackend based
  on user actions/events
Thick Client Application.
Technologies for Building RIAs
Key Technologies
    –
        Adobe Flex
    –
        Microsoft Silverlight
    –
        Java
        Applets/WebStart
    –
        AJAX
Other Technologies and
 Frameworks
    –
       Java FX
    –
       Open Laszlo
What is AJAX?
Asynchronous JavaScript And XML.

DHTML plus Asynchronous communication capability through
 XMLHttpRequest.
Pros
        Most viable RIA technology so far
        Tremendous industry momentum
        Several toolkits and frameworks are emerging
        No need to download code & no plug-in required
Cons
        Still browser incompatibility
        JavaScript is hard to maintain and debug.
Why AJAX?
Intuitive and natural user interaction.
          No clicking required
          Mouse movement is a sufficient event trigger
Partial screen update replaces the "click, wait, and refresh"
  user interaction model

Asynchronous communication replaces "synchronous request/
  response model."
Interrupted user
operation while
the data is being
fetched




Uninterrupted
user operation
while data is
being fetched
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Building RIAs using Java EE and AJAX
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.
Building RIAs using Java EE and AJAX
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
Challenges with typical AJAX development
JavaScript
        Not a strongly typed language
        Static Type checking?
        Code completion?
        Runtime-only bugs
 Browser compatibilities = “if/else soup”
 Juggling multiple languages (JavaScript, JSP tags, Java, XML,
 HTML etc.)
 Poor debugging
        Window.alert(), Firebug
Sample Javascript
What is Google Web Toolkit?
What is GWT?

GWT is an open source Java development framework.
Provides set of tools for building AJAX apps in the
 Java language.
GWT converts your Java source into equivalent
 JavaScript
History of Web Frameworks




Source : COMPARING KICK-ASS WEB FRAMEWORKS, Matt Raible
Advantages of GWT
No need to learn/use JavaScript language

No need to handle browser incompatibilities and quirks

No need to learn/use DOM APIs

No need to handle forward/backward buttons browser-history

No need to build commonly used Widgets

Can send complex Java types to/from the server

Leverage various tools of Java programming language for

writing/debugging/testing
Disadvantages of GWT
Only for Java developers.

Big learning curve

Cumbersome deployment

Nonstandard approach to integrate JavaScript

Unusual approach
GWT Implementation
GWT Features
A Basic API for creating Graphical User Interfaces (GUI)
         Similar to Swing.
API for Manipulating the Web browser's Document Object
 Model (DOM).
Java to JavaScript Compiler.
         Only required to know Java, XML and CSS. No JavaScript. No
         HTML. No PHP/ASP/CGI.
An environment for running and debugging GWT applications
 called the GWT shell (Hosted Mode).
GWT Application Layout
Module descriptor : module is the name GWT uses for an
  individual application configuration.
Public resources : these are all files that will be served publicly
  (e.g. HTML page, CSS and images)
Client-side code : this is the Java code that the GWT compiler
  translates into JavaScript, which will eventually run inside the
  browser.
Server-side code (optional)—this is the server part of your
  GWT application
Module Descriptor
Inherited modules : these entries are comparable to import
  statements in normal Java classes, but for GWT applications.
Entry point class : details which classes serve as the entry
  points (class implements the EntryPoint interface)
Source path entries : the module descriptor allows you to
  customize the location of the client-side code.
Public path entries : these allow you to handle public path
  items such as source path entries.
Deferred binding rules : more advanced setting
Module Descriptor : Sample (Main.gwt.xml)


<?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
<module>
 <module>
   <inherits name="com.google.gwt.user.User"/>
    <inherits name="com.google.gwt.user.User"/>
   <entry-point class="org.thaijavadev.client.MainEntryPoint"/>
    <entry-point class="org.thaijavadev.client.MainEntryPoint"/>
</module>
 </module>
The Entry Point Class
Before we start building our user interface, we need to
  understand the Entry Point Class.
Think of this class as the main class of your application with
  the java main() method that the JVM invokes first.
The Entry Point class contains onModuleLoad() method which
  is the method that the GWT compiler calls first.
The class implements com.google.gwt.core.client.EntryPoint
  interface.
UI Components & Event : Sample
public class ButtonExample implements EntryPoint {{
 public class ButtonExample implements EntryPoint
     public void onModuleLoad() {{
      public void onModuleLoad()
          final ToggleButton messageToggleButton == new ToggleButton("UP",
           final ToggleButton messageToggleButton    new ToggleButton("UP",
               "DOWN");
                "DOWN");
          RootPanel.get().add(messageToggleButton);
           RootPanel.get().add(messageToggleButton);
          Hyperlink alertLink == new Hyperlink("Alert", "alert");
           Hyperlink alertLink    new Hyperlink("Alert", "alert");
          alertLink.addClickListener(new ClickListener() {{
           alertLink.addClickListener(new ClickListener()
               public void onClick(Widget widget) {{
                public void onClick(Widget widget)
                  if (messageToggleButton.isDown()) {{
                   if (messageToggleButton.isDown())
                     Window.alert("HELLLLP!!!!");
                      Window.alert("HELLLLP!!!!");
                  }} else {{
                      else
                      Window.alert("Take it easy and relax");
                       Window.alert("Take it easy and relax");
                  }}
                  }}
          });
           });
          RootPanel.get().add(alertLink);
           RootPanel.get().add(alertLink);
     }}
}}
Public Resource (welcomeGWT.html) : Sample
<html>
 <html>
        <head>
         <head>
             <meta name='gwt:module'
              <meta name='gwt:module'
   content='org.thaijavadev.Main=org.thaijavadev.Main'>
    content='org.thaijavadev.Main=org.thaijavadev.Main'>
              <link rel="stylesheet" href="Main.css"/>
               <link rel="stylesheet" href="Main.css"/>
           <title>Main</title>
            <title>Main</title>
       </head>
        </head>
       <body>
        <body>
             <script language="javascript"
              <script language="javascript"
   src="org.thaijavadev.Main/org.thaijavadev.Main.nocache.js"></script>
    src="org.thaijavadev.Main/org.thaijavadev.Main.nocache.js"></script>
       </body>
        </body>
</html>
 </html>
Public Resource (Main.css) : Sample
root {
 root {
     display: block;
      display: block;

}}
.gwt-Label {{
 .gwt-Label
font-size: 9px;
 font-size: 9px;
}}


.gwt-Button, .gwt-TextBox, .gwt-PasswordTextBox {{
 .gwt-Button, .gwt-TextBox, .gwt-PasswordTextBox
font-size: 9px;
 font-size: 9px;
height: 19px;
 height: 19px;
width: 75px;
 width: 75px;
}}
GWT Components
GWT Components
Available widgets
HTML primitives (Button, Radio Button, Checkbox, TextBox,
 PasswordTextBox, TextArea, Hyperlink, ListBox, Table etc.)
PushButton, ToggleButton
MenuBar
Tree
TabBar
DialogBox
Available widgets
Panels (PopupPanel, StackPanel, HorizontalPanel,
 VerticalPanel, FlowPanel, VerticalSplitPanel,
 HorizontalSplitPanel, DockPanel, TabPanel, DisclosurePanel)
RichTextArea
SuggestBox (auto-complete)
Available widgets
Available widgets
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.
Events in GWT use the "listener interface" model similar to
  other user interface frameworks (like Swing)
Entry Point Class : Sample
public class MainEntryPoint implements EntryPoint {
 public class MainEntryPoint implements EntryPoint {

     public void onModuleLoad() {{
      public void onModuleLoad()
         final Label label == new Label("Hello, GWT!!!");
          final Label label    new Label("Hello, GWT!!!");
          final Button button == new Button("Click me!");
           final Button button    new Button("Click me!");

          button.addClickHandler(new ClickHandler() {{
           button.addClickHandler(new ClickHandler()
              public void onClick(ClickEvent event) {{
               public void onClick(ClickEvent event)
                      label.setVisible(!label.isVisible());
                       label.setVisible(!label.isVisible());
                 }}
          });
           });

          RootPanel.get().add(button);
           RootPanel.get().add(button);
          RootPanel.get().add(label);
           RootPanel.get().add(label);
     }}
}}
Simple Layout Panels
Panels are used to organize the layout of the various widgets
 we have covered so far.
GWT has several layout widgets that provide this functionality
The simple Layout Panels include:
     FlowPanel
     VerticalPanel
     HorizontalPanel
FlowPanel
It functions like the HTML layout
Child widgets of the FlowPanel are displayed horizontally and
 then wrapped to the next row down when there is not enough
 horizontal room left:

FlowPanel flowPanel == new FlowPanel();
 FlowPanel flowPanel      new FlowPanel();
for( int ii == 1; ii <= 20; i++ )) {{
 for( int       1;    <= 20; i++
    flowPanel.add(new Button("Button "" ++ String.valueOf(i)));
     flowPanel.add(new Button("Button       String.valueOf(i)));
}}
RootPanel.get().add(flowPanel);
 RootPanel.get().add(flowPanel);
HorizontalPanel and VerticalPanel

HorizontalPanel is similar to FlowPanel but uses
 scrollbar to display its widgets if there is no enough
 room instead of displacing to the next row
VerticalPanel organizes its child widgets in a vertical
 orientation
DockPanel : Sample
public class GWTasks implements EntryPoint {{
 public class GWTasks implements EntryPoint
     public void onModuleLoad() {{
      public void onModuleLoad()
           DockPanel mainPanel == new DockPanel();
            DockPanel mainPanel    new DockPanel();
           mainPanel.setBorderWidth(5);
            mainPanel.setBorderWidth(5);
           mainPanel.setSize("100%", "100%");
            mainPanel.setSize("100%", "100%");
           mainPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE);
            mainPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE);
           mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
            mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
           Widget header == createHeaderWidget();
            Widget header    createHeaderWidget();
           mainPanel.add(header, DockPanel.NORTH);
            mainPanel.add(header, DockPanel.NORTH);
           mainPanel.setCellHeight(header, "30px");
            mainPanel.setCellHeight(header, "30px");
           Widget footer == createFooterWidget();
            Widget footer    createFooterWidget();
           mainPanel.add(footer, DockPanel.SOUTH);
            mainPanel.add(footer, DockPanel.SOUTH);
           mainPanel.setCellHeight(footer, "25px");
            mainPanel.setCellHeight(footer, "25px");
           Widget categories == createCategoriesWidget();
            Widget categories    createCategoriesWidget();
           mainPanel.add(categories, DockPanel.WEST);
            mainPanel.add(categories, DockPanel.WEST);
           mainPanel.setCellWidth(categories, "150px");
            mainPanel.setCellWidth(categories, "150px");
           Widget tasks == createTasksWidget();
            Widget tasks    createTasksWidget();
DockPanel : Sample (Cont.)
          mainPanel.add(tasks, DockPanel.EAST);
           mainPanel.add(tasks, DockPanel.EAST);
          RootPanel.get().add(mainPanel);
           RootPanel.get().add(mainPanel);
               }}
     protected Widget createHeaderWidget() {{
      protected Widget createHeaderWidget()
          return new Label("Header");
           return new Label("Header");
     }}
     protected Widget createFooterWidget() {{
      protected Widget createFooterWidget()
          return new Label("Footer");
           return new Label("Footer");
     }}
     protected Widget createCategoriesWidget() {{
      protected Widget createCategoriesWidget()
          return new Label("Categories List");
           return new Label("Categories List");
     }}
     protected Widget createTasksWidget() {{
      protected Widget createTasksWidget()
          return new Label("Tasks List");
           return new Label("Tasks List");
     }}
}}
DockPanel : Sample Output
GWT-RPC
Communication with the Server

GWT support communication between the client-side browser
 and the server via GWT-RPC and Basic Ajax.
GWT use asynchronous communication to provide the rich UI
 experience expected from RIAs.
The details of communicating a message between client and
 server and vice versa can be abstracted away by frameworks
GWT RPC allows you to program your communication by
 calling a method on a Java interface.
GWT-RPC
GWT extends a browser’s capability to asynchronously
 communicate with the server by providing a remote procedure
 call (RPC) library.
Calls to the server are simplified by providing you with an
 interface of methods that can be called similarly to regular
 method calls.
GWT marshal the calls (convert to a stream of data) and send
 to the remote server.
At the server side, the data, is un-marshalled the method on
 the server is invoked
GWT-RPC
GWT uses a pure Java implementation.
In GWT, the RPC library is divided into two packages:
     com.google.gwt.user.client.rpc package used for client-side RPC
     support .
     com.google.gwt.user.server.rpc package used for server-side RPC
     support . The client side provides interfaces that you can use to tag.
When the client code is compiled to Javascript using the
 GWT compiler, the code required to do the RPC marshaling will
 be generated .
RPC Plumbing Diagram
Implementing GWT-RPC Services

Define an interface for your service that extends
 RemoteService and lists all your RPC methods.
 Define a class to implement the server-side code that extends
 RemoteServiceServlet and implements the interface you
 created above.
Define an asynchronous interface to your service to be called
 from the client-side code.
A client-side Java interface

Create a client-side Java interface that extends the
 RemoteService tag interface.


import com.google.gwt.user.client.rpc.RemoteService;
 import com.google.gwt.user.client.rpc.RemoteService;


public interface MyService extends RemoteService {{
 public interface MyService extends RemoteService
  public String myMethod(String s);
   public String myMethod(String s);
}}
Implement the remote method

Implement the service on the server-side by a class that
 extend RemoteServiceServlet.
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.example.client.MyService;
 import com.example.client.MyService;


public class MyServiceImpl extends RemoteServiceServlet implements
 public class MyServiceImpl extends RemoteServiceServlet implements
    MyService {{
     MyService


  public String myMethod(String s) {{
   public String myMethod(String s)
    // Do something interesting with 's' here on the server.
     // Do something interesting with 's' here on the server.
       return s;
        return s;
  }}
Asynchronous Interfaces

This interface defines the callback method that will be called
 when the server generates a response.


interface MyServiceAsync {{
 interface MyServiceAsync
  public void myMethod(String s, AsyncCallback<String> callback);
   public void myMethod(String s, AsyncCallback<String> callback);
}}
 }}
Making an RPC from the client

Instantiate the service interface using GWT.create().
Create an asynchronous callback object to be notified when
 the RPC has completed.
Make the call .
Making a Call: Sample
public class MainEntryPoint implements EntryPoint {{
 public class MainEntryPoint implements EntryPoint

    public MainEntryPoint() {{
     public MainEntryPoint()
    }}
    public void onModuleLoad() {{
     public void onModuleLoad()
        getService().myMethod("Hello World", callback);
         getService().myMethod("Hello World", callback);
    }}


    final AsyncCallback callback == new AsyncCallback() {{
     final AsyncCallback callback    new AsyncCallback()
            public void onSuccess(Object result) {{
             public void onSuccess(Object result)
                 Window.alert((String)result);
                  Window.alert((String)result);
            }}


            public void onFailure(Throwable caught) {{
             public void onFailure(Throwable caught)
                Window.alert("Communication failed");
                 Window.alert("Communication failed");
            }}
    };
     };
Making a Call: Sample (Cont.)

     public static MyServiceAsync getService(){
      public static MyServiceAsync getService(){

          MyServiceAsync service == (MyServiceAsync)
           MyServiceAsync service    (MyServiceAsync)
              GWT.create(MyService.class);
               GWT.create(MyService.class);

          ServiceDefTarget endpoint == (ServiceDefTarget) service;
           ServiceDefTarget endpoint    (ServiceDefTarget) service;
          String moduleRelativeURL == GWT.getModuleBaseURL() ++ "myservice";
           String moduleRelativeURL    GWT.getModuleBaseURL()    "myservice";
          endpoint.setServiceEntryPoint(moduleRelativeURL);
           endpoint.setServiceEntryPoint(moduleRelativeURL);
          return service;
           return service;
     }}


}}
Resources
Building Rich Internet Applications Using Google Web Toolkit
 (GWT), Karthik Shyamsunder, Oct 2008.
Introduction to Google Web Toolkit, Muhammad Ghazali.
Official Google Web Tool Kit Tutorial,
 http://code.google.com/webtoolkit/doc/latest/tutorial/
Beginning Google Web Toolkit from Novice to Professional,
 Apress, 2009
Thank you

   thananum@gmail.com
www.facebook.com/imcinstitute
   www.imcinstitute.com

More Related Content

What's hot (18)

PDF
Spring mvc
Guo Albert
 
ODP
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
PDF
Suportando Aplicações Multi-tenancy com Java EE
Rodrigo Cândido da Silva
 
PPTX
Integration of Backbone.js with Spring 3.1
Michał Orman
 
PPTX
Spring MVC
Emprovise
 
PDF
Java Web Programming [3/9] : Servlet Advanced
IMC Institute
 
PPT
CTS Conference Web 2.0 Tutorial Part 2
Geoffrey Fox
 
PDF
Lecture 11 Firebase overview
Maksym Davydov
 
PPT
Spring MVC Basics
Bozhidar Bozhanov
 
PPTX
Javatwo2012 java frameworkcomparison
Jini Lee
 
KEY
MVC on the server and on the client
Sebastiano Armeli
 
PDF
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
mfrancis
 
PDF
Java Web Programming [8/9] : JSF and AJAX
IMC Institute
 
PPT
Spring 3.x - Spring MVC
Guy Nir
 
PPTX
4. jsp
AnusAhmad
 
PDF
DataFX - JavaOne 2013
Hendrik Ebbers
 
PDF
The Big Picture and How to Get Started
guest1af57e
 
PDF
Java Web Programming [2/9] : Servlet Basic
IMC Institute
 
Spring mvc
Guo Albert
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
Suportando Aplicações Multi-tenancy com Java EE
Rodrigo Cândido da Silva
 
Integration of Backbone.js with Spring 3.1
Michał Orman
 
Spring MVC
Emprovise
 
Java Web Programming [3/9] : Servlet Advanced
IMC Institute
 
CTS Conference Web 2.0 Tutorial Part 2
Geoffrey Fox
 
Lecture 11 Firebase overview
Maksym Davydov
 
Spring MVC Basics
Bozhidar Bozhanov
 
Javatwo2012 java frameworkcomparison
Jini Lee
 
MVC on the server and on the client
Sebastiano Armeli
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
mfrancis
 
Java Web Programming [8/9] : JSF and AJAX
IMC Institute
 
Spring 3.x - Spring MVC
Guy Nir
 
4. jsp
AnusAhmad
 
DataFX - JavaOne 2013
Hendrik Ebbers
 
The Big Picture and How to Get Started
guest1af57e
 
Java Web Programming [2/9] : Servlet Basic
IMC Institute
 

Viewers also liked (8)

PDF
โอกาสและความท้าทายของ อุตสาหกรรมไอซีทีไทย ในเวทีอาเซี่ยน
IMC Institute
 
PDF
Data Rules
IMC Institute
 
PDF
Brain Shaper for Digital Revolution Era
IMC Institute
 
PDF
Java Web Programming [9/9] : Web Application Security
IMC Institute
 
PPT
Java Programming [3/12]: Control Structures
IMC Institute
 
PDF
List of Thai Companies for Business Match Making in Software Expo Asia
IMC Institute
 
PDF
E-Government
IMC Institute
 
PDF
Java Web Services [5/5]: REST and JAX-RS
IMC Institute
 
โอกาสและความท้าทายของ อุตสาหกรรมไอซีทีไทย ในเวทีอาเซี่ยน
IMC Institute
 
Data Rules
IMC Institute
 
Brain Shaper for Digital Revolution Era
IMC Institute
 
Java Web Programming [9/9] : Web Application Security
IMC Institute
 
Java Programming [3/12]: Control Structures
IMC Institute
 
List of Thai Companies for Business Match Making in Software Expo Asia
IMC Institute
 
E-Government
IMC Institute
 
Java Web Services [5/5]: REST and JAX-RS
IMC Institute
 
Ad

Similar to Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit (20)

PDF
Google Web Toolkit
Software Park Thailand
 
PPT
GWT
Lorraine JUG
 
PPTX
Gwt overview & getting started
Binh Bui
 
PPTX
Gwt session
Ahmed Akl
 
PPTX
Gwt session
Mans Jug
 
PDF
GWT - Building Rich Internet Applications Using OO Tools
barciszewski
 
PPT
Google Web Toolkit Introduction - eXo Platform SEA
nerazz08
 
PPT
GWT Training - Session 1/3
Faiz Bashir
 
PPT
GWT_Framework
Sonal Patil
 
PDF
Introduction to Google Web Toolkit - part 1
Muhammad Ghazali
 
PDF
GWT-Basics
tutorialsruby
 
PDF
GWT-Basics
tutorialsruby
 
PPTX
Google web toolkit ( Gwt )
Pankaj Bhasker
 
PPT
Introduction to Google Web Toolkit
Didier Girard
 
PPTX
GWT = easy AJAX
Olivier Gérardin
 
PDF
Gwt Presentation
rajakumar.tu
 
PDF
GWT training session 1
SNEHAL MASNE
 
PDF
Introduction to Google Web Toolkit
Jeppe Rishede
 
PDF
Devfest09 Cschalk Gwt
Chris Schalk
 
Google Web Toolkit
Software Park Thailand
 
Gwt overview & getting started
Binh Bui
 
Gwt session
Ahmed Akl
 
Gwt session
Mans Jug
 
GWT - Building Rich Internet Applications Using OO Tools
barciszewski
 
Google Web Toolkit Introduction - eXo Platform SEA
nerazz08
 
GWT Training - Session 1/3
Faiz Bashir
 
GWT_Framework
Sonal Patil
 
Introduction to Google Web Toolkit - part 1
Muhammad Ghazali
 
GWT-Basics
tutorialsruby
 
GWT-Basics
tutorialsruby
 
Google web toolkit ( Gwt )
Pankaj Bhasker
 
Introduction to Google Web Toolkit
Didier Girard
 
GWT = easy AJAX
Olivier Gérardin
 
Gwt Presentation
rajakumar.tu
 
GWT training session 1
SNEHAL MASNE
 
Introduction to Google Web Toolkit
Jeppe Rishede
 
Devfest09 Cschalk Gwt
Chris Schalk
 
Ad

More from IMC Institute (20)

PDF
นิตยสาร Digital Trends ฉบับที่ 14
IMC Institute
 
PDF
Digital trends Vol 4 No. 13 Sep-Dec 2019
IMC Institute
 
PDF
บทความ The evolution of AI
IMC Institute
 
PDF
IT Trends eMagazine Vol 4. No.12
IMC Institute
 
PDF
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformation
IMC Institute
 
PDF
IT Trends 2019: Putting Digital Transformation to Work
IMC Institute
 
PDF
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรม
IMC Institute
 
PDF
IT Trends eMagazine Vol 4. No.11
IMC Institute
 
PDF
แนวทางการทำ Digital transformation
IMC Institute
 
PDF
บทความ The New Silicon Valley
IMC Institute
 
PDF
นิตยสาร IT Trends ของ IMC Institute ฉบับที่ 10
IMC Institute
 
PDF
แนวทางการทำ Digital transformation
IMC Institute
 
PDF
The Power of Big Data for a new economy (Sample)
IMC Institute
 
PDF
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง
IMC Institute
 
PDF
IT Trends eMagazine Vol 3. No.9
IMC Institute
 
PDF
Thailand software & software market survey 2016
IMC Institute
 
PPTX
Developing Business Blockchain Applications on Hyperledger
IMC Institute
 
PDF
Digital transformation @thanachart.org
IMC Institute
 
PDF
บทความ Big Data จากบล็อก thanachart.org
IMC Institute
 
PDF
กลยุทธ์ 5 ด้านกับการทำ Digital Transformation
IMC Institute
 
นิตยสาร Digital Trends ฉบับที่ 14
IMC Institute
 
Digital trends Vol 4 No. 13 Sep-Dec 2019
IMC Institute
 
บทความ The evolution of AI
IMC Institute
 
IT Trends eMagazine Vol 4. No.12
IMC Institute
 
เพราะเหตุใด Digitization ไม่ตอบโจทย์ Digital Transformation
IMC Institute
 
IT Trends 2019: Putting Digital Transformation to Work
IMC Institute
 
มูลค่าตลาดดิจิทัลไทย 3 อุตสาหกรรม
IMC Institute
 
IT Trends eMagazine Vol 4. No.11
IMC Institute
 
แนวทางการทำ Digital transformation
IMC Institute
 
บทความ The New Silicon Valley
IMC Institute
 
นิตยสาร IT Trends ของ IMC Institute ฉบับที่ 10
IMC Institute
 
แนวทางการทำ Digital transformation
IMC Institute
 
The Power of Big Data for a new economy (Sample)
IMC Institute
 
บทความ Robotics แนวโน้มใหม่สู่บริการเฉพาะทาง
IMC Institute
 
IT Trends eMagazine Vol 3. No.9
IMC Institute
 
Thailand software & software market survey 2016
IMC Institute
 
Developing Business Blockchain Applications on Hyperledger
IMC Institute
 
Digital transformation @thanachart.org
IMC Institute
 
บทความ Big Data จากบล็อก thanachart.org
IMC Institute
 
กลยุทธ์ 5 ด้านกับการทำ Digital Transformation
IMC Institute
 

Recently uploaded (20)

PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Python basic programing language for automation
DanialHabibi2
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Python basic programing language for automation
DanialHabibi2
 

Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit

  • 1. Google Web Toolkit Assoc.Prof. Dr.Thanachart Numnonda Asst.Prof. Thanisa Kruawaisayawan www.imcinstitute.com July 2012
  • 2. Agenda RIA and AJAX What is Google Web Toolkit? GWT Implementation GWT Components GWT RPC
  • 4. Rich Internet Applications Web applications that have the features and functionality of traditional desktop applications Typically transfer the processing necessary for the user interface to the web client but keep the bulk of the data back o n the application server. Make asynchronous/synchronous calls to thebackend based on user actions/events Thick Client Application.
  • 5. Technologies for Building RIAs Key Technologies – Adobe Flex – Microsoft Silverlight – Java Applets/WebStart – AJAX Other Technologies and Frameworks – Java FX – Open Laszlo
  • 6. What is AJAX? Asynchronous JavaScript And XML. DHTML plus Asynchronous communication capability through XMLHttpRequest. Pros Most viable RIA technology so far Tremendous industry momentum Several toolkits and frameworks are emerging No need to download code & no plug-in required Cons Still browser incompatibility JavaScript is hard to maintain and debug.
  • 7. Why AJAX? Intuitive and natural user interaction. No clicking required Mouse movement is a sufficient event trigger Partial screen update replaces the "click, wait, and refresh" user interaction model Asynchronous communication replaces "synchronous request/ response model."
  • 8. Interrupted user operation while the data is being fetched Uninterrupted user operation while data is being fetched
  • 10. Building RIAs using Java EE and AJAX 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.
  • 11. Building RIAs using Java EE and AJAX 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
  • 12. Challenges with typical AJAX development JavaScript Not a strongly typed language Static Type checking? Code completion? Runtime-only bugs Browser compatibilities = “if/else soup” Juggling multiple languages (JavaScript, JSP tags, Java, XML, HTML etc.) Poor debugging Window.alert(), Firebug
  • 14. What is Google Web Toolkit?
  • 15. What is GWT? GWT is an open source Java development framework. Provides set of tools for building AJAX apps in the Java language. GWT converts your Java source into equivalent JavaScript
  • 16. History of Web Frameworks Source : COMPARING KICK-ASS WEB FRAMEWORKS, Matt Raible
  • 17. Advantages of GWT No need to learn/use JavaScript language No need to handle browser incompatibilities and quirks No need to learn/use DOM APIs No need to handle forward/backward buttons browser-history No need to build commonly used Widgets Can send complex Java types to/from the server Leverage various tools of Java programming language for writing/debugging/testing
  • 18. Disadvantages of GWT Only for Java developers. Big learning curve Cumbersome deployment Nonstandard approach to integrate JavaScript Unusual approach
  • 20. GWT Features A Basic API for creating Graphical User Interfaces (GUI) Similar to Swing. API for Manipulating the Web browser's Document Object Model (DOM). Java to JavaScript Compiler. Only required to know Java, XML and CSS. No JavaScript. No HTML. No PHP/ASP/CGI. An environment for running and debugging GWT applications called the GWT shell (Hosted Mode).
  • 21. GWT Application Layout Module descriptor : module is the name GWT uses for an individual application configuration. Public resources : these are all files that will be served publicly (e.g. HTML page, CSS and images) Client-side code : this is the Java code that the GWT compiler translates into JavaScript, which will eventually run inside the browser. Server-side code (optional)—this is the server part of your GWT application
  • 22. Module Descriptor Inherited modules : these entries are comparable to import statements in normal Java classes, but for GWT applications. Entry point class : details which classes serve as the entry points (class implements the EntryPoint interface) Source path entries : the module descriptor allows you to customize the location of the client-side code. Public path entries : these allow you to handle public path items such as source path entries. Deferred binding rules : more advanced setting
  • 23. Module Descriptor : Sample (Main.gwt.xml) <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?> <module> <module> <inherits name="com.google.gwt.user.User"/> <inherits name="com.google.gwt.user.User"/> <entry-point class="org.thaijavadev.client.MainEntryPoint"/> <entry-point class="org.thaijavadev.client.MainEntryPoint"/> </module> </module>
  • 24. The Entry Point Class Before we start building our user interface, we need to understand the Entry Point Class. Think of this class as the main class of your application with the java main() method that the JVM invokes first. The Entry Point class contains onModuleLoad() method which is the method that the GWT compiler calls first. The class implements com.google.gwt.core.client.EntryPoint interface.
  • 25. UI Components & Event : Sample public class ButtonExample implements EntryPoint {{ public class ButtonExample implements EntryPoint public void onModuleLoad() {{ public void onModuleLoad() final ToggleButton messageToggleButton == new ToggleButton("UP", final ToggleButton messageToggleButton new ToggleButton("UP", "DOWN"); "DOWN"); RootPanel.get().add(messageToggleButton); RootPanel.get().add(messageToggleButton); Hyperlink alertLink == new Hyperlink("Alert", "alert"); Hyperlink alertLink new Hyperlink("Alert", "alert"); alertLink.addClickListener(new ClickListener() {{ alertLink.addClickListener(new ClickListener() public void onClick(Widget widget) {{ public void onClick(Widget widget) if (messageToggleButton.isDown()) {{ if (messageToggleButton.isDown()) Window.alert("HELLLLP!!!!"); Window.alert("HELLLLP!!!!"); }} else {{ else Window.alert("Take it easy and relax"); Window.alert("Take it easy and relax"); }} }} }); }); RootPanel.get().add(alertLink); RootPanel.get().add(alertLink); }} }}
  • 26. Public Resource (welcomeGWT.html) : Sample <html> <html> <head> <head> <meta name='gwt:module' <meta name='gwt:module' content='org.thaijavadev.Main=org.thaijavadev.Main'> content='org.thaijavadev.Main=org.thaijavadev.Main'> <link rel="stylesheet" href="Main.css"/> <link rel="stylesheet" href="Main.css"/> <title>Main</title> <title>Main</title> </head> </head> <body> <body> <script language="javascript" <script language="javascript" src="org.thaijavadev.Main/org.thaijavadev.Main.nocache.js"></script> src="org.thaijavadev.Main/org.thaijavadev.Main.nocache.js"></script> </body> </body> </html> </html>
  • 27. Public Resource (Main.css) : Sample root { root { display: block; display: block; }} .gwt-Label {{ .gwt-Label font-size: 9px; font-size: 9px; }} .gwt-Button, .gwt-TextBox, .gwt-PasswordTextBox {{ .gwt-Button, .gwt-TextBox, .gwt-PasswordTextBox font-size: 9px; font-size: 9px; height: 19px; height: 19px; width: 75px; width: 75px; }}
  • 30. Available widgets HTML primitives (Button, Radio Button, Checkbox, TextBox, PasswordTextBox, TextArea, Hyperlink, ListBox, Table etc.) PushButton, ToggleButton MenuBar Tree TabBar DialogBox
  • 31. Available widgets Panels (PopupPanel, StackPanel, HorizontalPanel, VerticalPanel, FlowPanel, VerticalSplitPanel, HorizontalSplitPanel, DockPanel, TabPanel, DisclosurePanel) RichTextArea SuggestBox (auto-complete)
  • 34. 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. Events in GWT use the "listener interface" model similar to other user interface frameworks (like Swing)
  • 35. Entry Point Class : Sample public class MainEntryPoint implements EntryPoint { public class MainEntryPoint implements EntryPoint { public void onModuleLoad() {{ public void onModuleLoad() final Label label == new Label("Hello, GWT!!!"); final Label label new Label("Hello, GWT!!!"); final Button button == new Button("Click me!"); final Button button new Button("Click me!"); button.addClickHandler(new ClickHandler() {{ button.addClickHandler(new ClickHandler() public void onClick(ClickEvent event) {{ public void onClick(ClickEvent event) label.setVisible(!label.isVisible()); label.setVisible(!label.isVisible()); }} }); }); RootPanel.get().add(button); RootPanel.get().add(button); RootPanel.get().add(label); RootPanel.get().add(label); }} }}
  • 36. Simple Layout Panels Panels are used to organize the layout of the various widgets we have covered so far. GWT has several layout widgets that provide this functionality The simple Layout Panels include: FlowPanel VerticalPanel HorizontalPanel
  • 37. FlowPanel It functions like the HTML layout Child widgets of the FlowPanel are displayed horizontally and then wrapped to the next row down when there is not enough horizontal room left: FlowPanel flowPanel == new FlowPanel(); FlowPanel flowPanel new FlowPanel(); for( int ii == 1; ii <= 20; i++ )) {{ for( int 1; <= 20; i++ flowPanel.add(new Button("Button "" ++ String.valueOf(i))); flowPanel.add(new Button("Button String.valueOf(i))); }} RootPanel.get().add(flowPanel); RootPanel.get().add(flowPanel);
  • 38. HorizontalPanel and VerticalPanel HorizontalPanel is similar to FlowPanel but uses scrollbar to display its widgets if there is no enough room instead of displacing to the next row VerticalPanel organizes its child widgets in a vertical orientation
  • 39. DockPanel : Sample public class GWTasks implements EntryPoint {{ public class GWTasks implements EntryPoint public void onModuleLoad() {{ public void onModuleLoad() DockPanel mainPanel == new DockPanel(); DockPanel mainPanel new DockPanel(); mainPanel.setBorderWidth(5); mainPanel.setBorderWidth(5); mainPanel.setSize("100%", "100%"); mainPanel.setSize("100%", "100%"); mainPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE); mainPanel.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE); mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); Widget header == createHeaderWidget(); Widget header createHeaderWidget(); mainPanel.add(header, DockPanel.NORTH); mainPanel.add(header, DockPanel.NORTH); mainPanel.setCellHeight(header, "30px"); mainPanel.setCellHeight(header, "30px"); Widget footer == createFooterWidget(); Widget footer createFooterWidget(); mainPanel.add(footer, DockPanel.SOUTH); mainPanel.add(footer, DockPanel.SOUTH); mainPanel.setCellHeight(footer, "25px"); mainPanel.setCellHeight(footer, "25px"); Widget categories == createCategoriesWidget(); Widget categories createCategoriesWidget(); mainPanel.add(categories, DockPanel.WEST); mainPanel.add(categories, DockPanel.WEST); mainPanel.setCellWidth(categories, "150px"); mainPanel.setCellWidth(categories, "150px"); Widget tasks == createTasksWidget(); Widget tasks createTasksWidget();
  • 40. DockPanel : Sample (Cont.) mainPanel.add(tasks, DockPanel.EAST); mainPanel.add(tasks, DockPanel.EAST); RootPanel.get().add(mainPanel); RootPanel.get().add(mainPanel); }} protected Widget createHeaderWidget() {{ protected Widget createHeaderWidget() return new Label("Header"); return new Label("Header"); }} protected Widget createFooterWidget() {{ protected Widget createFooterWidget() return new Label("Footer"); return new Label("Footer"); }} protected Widget createCategoriesWidget() {{ protected Widget createCategoriesWidget() return new Label("Categories List"); return new Label("Categories List"); }} protected Widget createTasksWidget() {{ protected Widget createTasksWidget() return new Label("Tasks List"); return new Label("Tasks List"); }} }}
  • 43. Communication with the Server GWT support communication between the client-side browser and the server via GWT-RPC and Basic Ajax. GWT use asynchronous communication to provide the rich UI experience expected from RIAs. The details of communicating a message between client and server and vice versa can be abstracted away by frameworks GWT RPC allows you to program your communication by calling a method on a Java interface.
  • 44. GWT-RPC GWT extends a browser’s capability to asynchronously communicate with the server by providing a remote procedure call (RPC) library. Calls to the server are simplified by providing you with an interface of methods that can be called similarly to regular method calls. GWT marshal the calls (convert to a stream of data) and send to the remote server. At the server side, the data, is un-marshalled the method on the server is invoked
  • 45. GWT-RPC GWT uses a pure Java implementation. In GWT, the RPC library is divided into two packages: com.google.gwt.user.client.rpc package used for client-side RPC support . com.google.gwt.user.server.rpc package used for server-side RPC support . The client side provides interfaces that you can use to tag. When the client code is compiled to Javascript using the GWT compiler, the code required to do the RPC marshaling will be generated .
  • 47. Implementing GWT-RPC Services Define an interface for your service that extends RemoteService and lists all your RPC methods.  Define a class to implement the server-side code that extends RemoteServiceServlet and implements the interface you created above. Define an asynchronous interface to your service to be called from the client-side code.
  • 48. A client-side Java interface Create a client-side Java interface that extends the RemoteService tag interface. import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService; public interface MyService extends RemoteService {{ public interface MyService extends RemoteService public String myMethod(String s); public String myMethod(String s); }}
  • 49. Implement the remote method Implement the service on the server-side by a class that extend RemoteServiceServlet. import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.example.client.MyService; import com.example.client.MyService; public class MyServiceImpl extends RemoteServiceServlet implements public class MyServiceImpl extends RemoteServiceServlet implements MyService {{ MyService public String myMethod(String s) {{ public String myMethod(String s) // Do something interesting with 's' here on the server. // Do something interesting with 's' here on the server. return s; return s; }}
  • 50. Asynchronous Interfaces This interface defines the callback method that will be called when the server generates a response. interface MyServiceAsync {{ interface MyServiceAsync public void myMethod(String s, AsyncCallback<String> callback); public void myMethod(String s, AsyncCallback<String> callback); }} }}
  • 51. Making an RPC from the client Instantiate the service interface using GWT.create(). Create an asynchronous callback object to be notified when the RPC has completed. Make the call .
  • 52. Making a Call: Sample public class MainEntryPoint implements EntryPoint {{ public class MainEntryPoint implements EntryPoint public MainEntryPoint() {{ public MainEntryPoint() }} public void onModuleLoad() {{ public void onModuleLoad() getService().myMethod("Hello World", callback); getService().myMethod("Hello World", callback); }} final AsyncCallback callback == new AsyncCallback() {{ final AsyncCallback callback new AsyncCallback() public void onSuccess(Object result) {{ public void onSuccess(Object result) Window.alert((String)result); Window.alert((String)result); }} public void onFailure(Throwable caught) {{ public void onFailure(Throwable caught) Window.alert("Communication failed"); Window.alert("Communication failed"); }} }; };
  • 53. Making a Call: Sample (Cont.) public static MyServiceAsync getService(){ public static MyServiceAsync getService(){ MyServiceAsync service == (MyServiceAsync) MyServiceAsync service (MyServiceAsync) GWT.create(MyService.class); GWT.create(MyService.class); ServiceDefTarget endpoint == (ServiceDefTarget) service; ServiceDefTarget endpoint (ServiceDefTarget) service; String moduleRelativeURL == GWT.getModuleBaseURL() ++ "myservice"; String moduleRelativeURL GWT.getModuleBaseURL() "myservice"; endpoint.setServiceEntryPoint(moduleRelativeURL); endpoint.setServiceEntryPoint(moduleRelativeURL); return service; return service; }} }}
  • 54. Resources Building Rich Internet Applications Using Google Web Toolkit (GWT), Karthik Shyamsunder, Oct 2008. Introduction to Google Web Toolkit, Muhammad Ghazali. Official Google Web Tool Kit Tutorial, http://code.google.com/webtoolkit/doc/latest/tutorial/ Beginning Google Web Toolkit from Novice to Professional, Apress, 2009
  • 55. Thank you [email protected] www.facebook.com/imcinstitute www.imcinstitute.com