You are on page 1of 20

Seiya Kawashima

Eric West
Paul Zolnierczyk
Overview
 What is GWT?
 The motivation behind GWT
 GWT Setup
 Code Example
 Strengths and Weaknesses
 Conclusion
What is the GWT?
 Core
 Java-to-Javascript compiler
 Functionality
 Automates client-server communication
 Not reliant on traditional postbacks (page loads)
 Utilizes AJAX (Asynchronous JavaScript and XML)
 Widget library (UI components)
 Really simple RPC
 Use serializable classes
 GWT does the rest
 Both client and server agree on object
 No XML definition required
Motivation
 Avoid Javascript, use Java
 Javascript is extremely difficult to debug.
 No compile time errors
 Javascript can mimic an OO style, but objects are not aware of
eachother until runtime invocation.
 All the perks of Java and your favorite IDE
 Refactoring
 Debugging (breakpoints)
 Unit testing
 Javadocs
 OO design patterns
Motivation Continued
 Simplify the development process
 Building a complex app is difficult enough. Connecting
the client and service using AJAX can be a nightmare.
 Create a rich UI that works within a browser
 Automate web native functionality
 Back and Forward buttons
 RESTful urls
 Links represent a state in the web app that can be revisited.

 CSS Styles
 Keyboard support
A conventional (simple) AJAX setup
<div id="ajax_output"> document.getElementById(
Waiting to be replaced by Ajax Call "ajax_output").innerHTML
</div> = xmlHttp.responseText;
}
<script type="text/javascript"> } catch (e) {
var xmlHttp=null; document.getElementById("ajax_output").
different browser innerHTML = "Error on Ajax return call : " + e.description;
try { }
// Firefox, Opera 8.0+, Safari, IE7+
xmlHttp = new XMLHttpRequest(); }
} catch (e) { xmlHttp.open("get","pages/index.html");
// Internet Explorer xmlHttp.open(RequestType, Source);
try { xmlHttp.send(null);
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) { </script>
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}

xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState == 4)
try {
if (xmlHttp.status == 200) {

source: Wikipedia - AJAX


http://en.wikipedia.org/wiki/AJAX
AJAX using prototype
<script type="text/javascript">
//<![CDATA[

var handlerAddress = 'http://www.yoursite.com/AjaxHandler.ashx';

function populateList()
{
new Ajax.Updater('listcontainer', handlerAddress, {
method: 'get',
parameters: {
filter1: document.getElementById("dropDownList1").value,
filter2: document.getElementById("dropDownList2").value
},
onLoading: function() {
loadingImgage.className = "";
},
onComplete: function() {
loadingImg.className = "hidden";
},
onFailure: function(){
alert("An error occurred completing your request.");
}
});
}
//]]>
</script>
Really simple RPC

source: Google Web Toolkit Web site


http://code.google.com/webtoolkit/documentation/com.google.gwt.doc.DeveloperGuide.RemoteProcedureCalls.html
GWT Integration in Eclipse
 1. Download Google Web Toolkit.
 2. Unzip the file using WinZip, tar command or others
that you prefer to unzip
 3. Type "projectCreator -eclipse YourProject" on
cmd.exe or a terminal
 --- This command generates a new eclipse project for
you.
GWT Integration Cont’d
 4. Type "applicationCreator -eclipse YourProject
com.mycompany.client.YourApplication“
 --- This command generates a GWT project in eclipse.

 5. Open eclipse
GWT Integration Cont’d
 6. Click File -> Import  7. Choose "Existing
menu Projects into Workspace“
GWT Integration Cont’d
 8. Enter the directory that has ".project" file.
GWT Integration Cont’d
 9. You see your ‘YourProject' project on eclipse
How to Build and Call GWT RPC
Service
 There are always three steps involved to make GWT RPC service.
Defining the service's synchronous and asynchronous interface
(client side)

 Implementing the service (server side)

 Calling the service (client side)

 On our sample code:


Synchronous interface - MyService.java
Asynchronous interface - MyServiceAsync.java
Implementation of Service - MyServiceImpl.java
Calling the Service - YourApplication.java
Code Example
Strengths of GWT
 GWT's defining attribute is the Java-to-JavaScript
compiler
 Develop in Java, deploy in Java-scripts

 All your user-interface code exists on the client


browser. Improves response time by reducing traffic
going to the middle-tier
Strengths Cont’d
 An alternate environment to facilitate debugging

 Can be used to create AJAX components

 Applications are created in 100 percent java against a


set of API’s that mimic the end user environment.

 Maven users can build GWT applications using the


gwt-maven plugin
Weaknesses
 Provides a method of getting from the client to the
server where all code necessary to be executed is
already on the client.

 GWT uses RPC to accomplish the tasks that are


related to your application.

 Usually end up looking like Google Web Sites.


Conclusion
 If you’re looking for an easy to pick-up (assuming you
know java), cross-platform, supports Eclipse and is
Free. Google Web Toolkit is your answer. However,
please understand GWT should not be used at an
Enterprise level, it is geared towards smaller
applications.
Questions?

You might also like