SlideShare una empresa de Scribd logo
1 de 55
Descargar para leer sin conexión
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
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

Más contenido relacionado

La actualidad más candente

Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
Michał Orman
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
mfrancis
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
Guy Nir
 

La actualidad más candente (18)

Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
Suportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EESuportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EE
 
Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1Integration of Backbone.js with Spring 3.1
Integration of Backbone.js with Spring 3.1
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2
 
Lecture 11 Firebase overview
Lecture 11 Firebase overviewLecture 11 Firebase overview
Lecture 11 Firebase overview
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
 
MVC on the server and on the client
MVC on the server and on the clientMVC on the server and on the client
MVC on the server and on the client
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
4. jsp
4. jsp4. jsp
4. jsp
 
DataFX - JavaOne 2013
DataFX - JavaOne 2013DataFX - JavaOne 2013
DataFX - JavaOne 2013
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 

Destacado

โอกาสและความท้าทายของ อุตสาหกรรมไอซีทีไทย ในเวทีอาเซี่ยน
โอกาสและความท้าทายของ อุตสาหกรรมไอซีทีไทย  ในเวทีอาเซี่ยนโอกาสและความท้าทายของ อุตสาหกรรมไอซีทีไทย  ในเวทีอาเซี่ยน
โอกาสและความท้าทายของ อุตสาหกรรมไอซีทีไทย ในเวทีอาเซี่ยน
IMC Institute
 

Destacado (8)

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

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

Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
george.james
 
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
Fred Sauer
 
Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web Toolkit
Didier Girard
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
Mahmoud Hamed Mahmoud
 
Google Dev Day2007
Google Dev Day2007Google Dev Day2007
Google Dev Day2007
lucclaes
 

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

GWT
GWTGWT
GWT
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
Google Web Toolkit Introduction - eXo Platform SEA
Google Web Toolkit Introduction - eXo Platform SEAGoogle Web Toolkit Introduction - eXo Platform SEA
Google Web Toolkit Introduction - eXo Platform SEA
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
 
Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2Javascript as a target language - GWT KickOff - Part 2/2
Javascript as a target language - GWT KickOff - Part 2/2
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3
 
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
 
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter LehtoJavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
 
Introduction to Google Web Toolkit
Introduction to Google Web ToolkitIntroduction to Google Web Toolkit
Introduction to Google Web Toolkit
 
Beyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 AppsBeyond HTML: Tools for Building Web 2.0 Apps
Beyond HTML: Tools for Building Web 2.0 Apps
 
GWT 2 Is Smarter Than You
GWT 2 Is Smarter Than YouGWT 2 Is Smarter Than You
GWT 2 Is Smarter Than You
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Hybrid app
Hybrid appHybrid app
Hybrid app
 
YaJUG: What's new in GWT2
YaJUG: What's new in GWT2YaJUG: What's new in GWT2
YaJUG: What's new in GWT2
 
Vaadin & Web Components
Vaadin & Web ComponentsVaadin & Web Components
Vaadin & Web Components
 
GWT = easy AJAX
GWT = easy AJAXGWT = easy AJAX
GWT = easy AJAX
 
Html5
Html5Html5
Html5
 
Google Dev Day2007
Google Dev Day2007Google Dev Day2007
Google Dev Day2007
 

Más de IMC Institute

Más de IMC Institute (20)

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

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

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
  • 9.
  • 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 thananum@gmail.com www.facebook.com/imcinstitute www.imcinstitute.com