2. Topics Covered
• Short Introduction to GWT
• Architectural Overview
• Features of GWT
• Why, When & Who’s use GWT ?
• Simple Code Example
• Server Communication using GWT – RPC
• Intro of Various Web Frameworks
4. Overview of GWT
• Google announced GWT @ JavaOne Conference
in 2006 & on 16 May 2006 GWT 1.0 was released.
• Latest version is GWT 2.1.1 on 17 Dec 2010.
• Open source(Apache 2.0 Liscense) Java s/w
dévelopement framework.
• Allows web developers to create and maintain
complex JavaScript front-end applications.
• Supported by all the java IDE : Eclipse, NetBeans,
IntelliJ IDEA, JDeveloper… etc.
• Once the code is finished the GWT compiler
translates the Java code into Javascript.
5. • Applications can be run in two modes.
1) Development mode (Hosted mode): The
application is run as Java byte code within the Java
Virtual Machine (JVM). Used for development,
supporting hot swapping of code and debugging.
2) Web mode : Application is translated into
javascript & HTML code and can be deployed on a
web server.
• Uses MVC Design Pattern
• The based line : ‘’ First the user, second the
developer ’’ - Bruce Johnson.
6. GWT Architecture
JRE GWT Web Class
Emulation UI Class Libraries
Library library
(java.lang
and java.util)
Java-to- hosted web Development
JavaScript browser tools
Compiler Designer
8. Major Components Include
1. GWT Java-to-JavaScript Compiler
Translates the Java programming language to the
JavaScript programming language.
2. GWT Hosted Web Browser
Allows the developers to run and execute GWT
applications in hosted mode. It is commonly used
for debugging.
9. Components cont…..
3. JRE emulation library
JavaScript implementations of the commonly used
classes in the Java standard class library like java.lang
and a subset of the java.util package classes.
4. GWT Web UI class library
A set of custom interfaces & classes for creating
widgets.
14. Why GWT ?
• No need to learn/use Javacript language.
• No need to handle browser incompatibilities.
• Fast, responsive rich interface.
• Easy on the developer.
• A GWT application doesn’t need a server.
• A number of libraries are available for GWT,
by Google and third parties which extends
GWT features.
31. Run Demo Application – cont.
Run hello_gwt
Run hello_gwt
Check Console tab to confirm if the server is ready to use or not
Check Console tab to confirm if the server is ready to use or not
Click Development Mode tab to copy the testing url
Click Development Mode tab to copy the testing url
31
32. Run Demo Application – cont.
Click Send button
Click Send button
Show this popup window
Show this popup window
32
45. Testing
Compile the GWT project
Compile the GWT project
Run login.html
Run login.html
Click compile button
Click compile button
45
46. Testing – cont.
Type in user name with incorrect password, and click Login button
Type in user name with incorrect password, and click Login button
46
47. Testing – cont.
Type in user name with correct password, and click Login button
Type in user name with correct password, and click Login button
47
48. Testing – cont.
Click Reset button to clear data
Click Reset button to clear data
48
55. 1. Write Two Service Interface
Files
• Synchronous interface
@RemoteServiceRelativePath(”gwtservice")
public interface MyHelloService extends RemoteService {
public String sayHello(String s);
}
• Asynchronous interface
// Has to be named as <Synchronous-interface>Async.
// Has to pass AsyncCallback object as the last parameter.
// The return type is always void.
interface MyHelloServiceAsync {
public void sayHello(String s, AsyncCallback callback);
}
56. 2. Implement the Service
• Extends RemoteServiceServlet and
implements the service interface
public class MyHelloServiceImpl extends
RemoteServiceServlet
implements MyHelloService {
// Provide implementation logic.
public String sayHello(String s) {
return "Hello, " + s + "!";
}
}
57. 3. Configure Service in Module
Configuration File
<module><inherits
name=“com.google.gwt.user.User”/>
<entry-point
class=“com.google.gwt.sample.hello.client.Hello”/>
<servlet path=‘/hellorpc’
class=‘com.google.gwt.sample.hello.server.HelloServi
ceImpl’>
</module>
58. 4. Make a call from Client
• Instantiate an client proxy (an object of the
type of asynch. service interface) using
GWT.create()
• Create an asynchronous callback object to
be notified when the RPC has completed
• Make the call from the client
59. a. Instantiate Service Interface using
GWT.create()
public void menuCommandsayHello(String msg) {
MyHelloServiceAsync myhelloService =
GWT.create(MyHelloService.class);
60. b. Make the Call with an asynchronous
callback object
public void menuCommandsayhello(String msg) {
...
// (d) Make the call. Control flow will continue immediately and later
// 'callback' will be invoked when the RPC completes.
myhelloService.sayHello(msg, new AsyncCallback() {
public void onSuccess(Object result) {
// update page with server response data
}
public void onFailure(Throwable caught) {
// handle failure
}
});
}
61. List of various web frameworks
1. Struts
2. Spring
3. JSF
4. Blueshoes
5. Django
6. Pylons
7. Codeigniter
8. YUI
9. 52framework
62. Spring
• Java web framework
• Lightweight container to develop & deploy
enterprise application.
• Alternative for EJB’s & it uses only Plain Old Java
Object’s(POJO) as a component.
• Uses 2 types of programming techniques -
1) Inversion Control (Dependency Injection).
2) Aspect Oriented Programming.
• More popular because of its simplicity.
• More flexible to add persistence layer.
63. 52framework
• CSS framework
• Contains all nav, header, section, article,
footer which are basic HTML5 tags with full
documentation & growing community.
• Features like rounded corners, text-shadow,
box-shadow, grid system, html5 markup, css
reset.
64. Codeigniter
• Powerful PHP framework
• Very small footprint built for PHP coders who
need a simple & elegant toolkit to create full-
featured web applications.
• Mainly used for developers who lives in real
world to share hosting accounts & clients with
deadline and if you are tired from
undocumented frameworks.
65. Django
• Django 1.2 released on 17 May, 2010.
• High level python framework encourages rapid
development & clean pragmatic design.
• Framework used for perfectionists with
deadlines.
• www.djangoproject.com
• It makes easy to build web app more quickly with
less code.
• Focuses on automating as much as possible and
adhering to DRY(DON’T REPEAT YOURELF)
66. Documentation
• GWT Reference -
http://code.google.com/webtoolkit/
• Active Forum -
http://groups.google.com/group/Google-Web-Toolkit
• GWT Blog -
http://googlewebtoolkit.blogspot.com/
• On GWT, Tracking news on GWT -
http://www.ongwt.com/
• Millions of download
• Tones of Books
GWT Java-to-JavaScript Compiler GWT Hosted Web Browser GWT Designer JRE emulation library GWT contains JavaScript implementations of the most widely used classes in the Java standard class library GWT Web UI class library Similar to Swing UI Parses the original Java code Full parser, almost all Java constructs will be parsed correctly. Generates a full Abstract Syntax Tree (AST) GWT's compiler isn't a parlor trick, it's a real code parser and cross-language compiler Performs optimization, dead-code elimination, dynamic analysis, and other code fixups The generated JS is fast and efficient, sometimes faster than what you might write yourself Optimization All code is optimized, including some unusual tricks (like turning some methods into wrapped statics) Dead-Code Elimination Remove any code that cannot be reached, or always returns the same value(s) Javascript Generation Generate Javascript, including all necessary browser-specific checks and workarounds Javascript obfuscation and size reduction Javascript is (optionally) obfuscated to protect your trade-secrets, and to reduce it's size