Tuesday, January 24, 2012

Understanding GWT

What is GWT?

GWT is an open source Java development framework for developing Ajax based internet applications
Write, run, test, and debug everything in Java!
GWT Compiler translates Java code into JavaScript that is compatible with any browsers
An Open Source licensed under Apache 2.0 license

GWT Features

Dynamic & Reusable components
Simple RPC
Real Debugging
Browser Compatible
JUnit integration
Internationalization
JSNI – Java Script Native Interface 

Inside GWT

GWT comprises of mainly two components one is Class Libraries and another Development Tools.
The following picture gives more idea.



GWT User Interface

GWT UI comprises of Widgets, Layouts based on Panels (vertical, horizontal, scroll, tab etc.) and
Event Handlers/Listeners (Change, Click, Focus, Keyboard, Mouse, Scroll, Tab) 

How does GWT work?

GWT makes the web pages asynchronous unlike traditional html based web sites. Have a look at this picture.




GWT RPC



Running GWT Applications

GWT applications can be run in two modes
    1. Hosted mode
        -Runs as java byte code within the  JVM
        -Use this mode for debugging
    2. Web Mode
        -Runs as pure JavaScript

What does GWT supply?

GWT ships with following utilities
-Command-line utilities:
-projectCreator – make a project
-applicationCreator – generates starter application
-i18nCreator – generates internationalization scripts
-junitCreator – generates JUnit test & scripts for testing
- Platform Development Jar:  gwt-dev-xxx.jar ( where xxx is win32, linux, mac )
- Deployment Jar: gwt-user.jar
-  Sample Applications
- API Documentation 

GWT project structure
 com/example/app             -  Root project package. This package contains all the module files.
com/example/app/client   - Sub-package containing all the client-side source code.
com/example/app/server - Sub-package containing all the server-side source code
com/example/app/public  - Static resources



What is GWT Module?

A module bundles together all the configuration needed to use your code in a GWT project.
XML descriptor file ending with the .gwt.xml extension The contents include:
Inherited modules
An entry point application class name
Source Path entries
Public Path entries  

Working of GWT Application


 
Page loading in hosted mode

1. The Shell program opens a hosted browser window, which loads MyApp.html.
2. MyApp.html loads gwt.js with a <script> tag.
3. gwt.js scans MyApp.html and parses out the <meta name=’gwt:module’> to get the module name.
4. GWT reads the module file (MyApp.gwt.xml) to find the name of the EntryPoint class (MyApp).
5. The MyApp class is instantiated and its onModuleLoad module is called. Your application begins.
6. Your application code makes calls into the GWT run-time library (gwt-user.jar), which is also Java code.
7. Code in gwt-user.jar manipulates the hosted browser’s DOM to add UI components to the web page, and redirects all browser events back to the Java application code. 

JSNI
Writing Native Java Script Methods
public static native void alert(String msg)
     /*-{$wnd.alert(msg); }-*/;
Syntax:
    [instance-expr.]@class-name::field-name  

Server communication
Server communication happens through RPC, HTTP Requests and Gdata feeds (In JSON format)



What is GData?
A new standard Google protocol for reading and writing data on the web
GData is a new protocol based on Atom 1.0 and RSS 2.0.
To send a query to a server and receive a response containing a list of matching results
Blogger, Calendar, Spreadsheets, and Google Base can provide feed data in JSON format 

Advantages

No JavaScript syntax errors - No JavaScript programming at all!
Any java development tools can be used for creating GWT applications, for example Eclipse etc
Can use complex Java on the client
Reduced development time
The JavaScript generated out of GWT applications is cross browser compliant
Set of  reusable widgets
Less load on the server since all the UI generation happens at the client side
Better performance (Less network load)
GWT applications are comparatively  fast
Better end user experience with GWT applications
Ability to interface hand written JavaScript into java code (JSNI)
Excellent browser-to-server RPC 

Limitations

Big learning curve
Poorly documented process to deploy on a regular Java-based Web servers.
You never put direct JavaScript in your HTML. Instead, you use JSNI to wrap JavaScript in Java.
Most Ajax environments use JavaScript on the client and have a choice for the server. GWT is based entirely around Java.
Not all features of Java are supported in GWT. Example: multithreading
Client side code should be Java 1.4 or older compatible
Licensing terms & conditions
It is still evolving technology, advanced features like zooming, animations are not present currently.
Security issue

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...