Download - Gwt session
- 1. Google Web Toolkit(GWT) by Sherif Elsbaey
2. AGENDA Introducing GWT Discover the GWTs benefits,
capabilitiesand limitations Building User Interface GWT Widgets
Event handling Apply styles 3. AGENDA Client-Side RPC Architecture
GWT RPC Serializable type Handling Exception Create, develop,
execute and deploy GWTApplications History management
Internationalization JUnit Testing Javascript Native Interface
(JSNI) 4. AGENDA GWT Best Practices Security Issues Performance
Concerns The GWT Incremental-command class Caching in GWT GWT
Design Considerations GWT Pitfalls and Issues 5. Introducing GWT 6.
WHAT IS GWT? Java software development framework that makes writing
AJAX applications easy Google announced GWT at the JavaOne 2006 Let
you develop and debug AJAX applications in the Java language using
Java development tools Eclipse, Netbeans, IntelliJ, Provides
Java-to-Javascript compiler and development mode that helps you
debug your GWT applications 7. GWT SDK & TOOLS GWT SDK:
contains Java API libraries, compiler, development server and tools
Plugin for Eclipse: provides IDE support for GWT and App Engine web
projects Some other tools:GWT DesignerSpeed Tracer 8. TWO MODES OF
RUNNING GWT APPDevelopment mode (hosted mode)GWT application is run
as Java bytecode within JVMTake advantage of Java
debuggingProduction mode (web mode)Your GWT application is run as
pure Javascript and HTMLcompiled from original Java source codeEnd
user will only see the web mode version of yourapplication 9.
Discover the GWTs benefits, capabilities and limitations 10.
BENEFITS Develop Rich Web Apps, utilize client CPUs GWT is ultimate
Ajax Take advantage from rich built-in Widgets Build new generation
of distributed apps GWT transmits a tiny fraction of data compared
to traditionalapplications (should really be compared to real
contenders JavaApplets/Flex/Silverlight) Leverage various tools of
Java programming for writing,debugging, testing Ex: Eclipse,
IntelliJ, Netbeans, No need to take care of browser
incompatibilities and quirksGWT compiler handles them Support
browser history, backward, forward 11. CAPABILITIES Java-based
Object-Oriented designs are easier to communicateand understand.
Take advantage of Java refactoring, code completion, ... No need to
write excellent Javascript code Leverage your Java programming
knowledge JUnit integration Internationalization DOM management 12.
LIMITATIONS Not all of JDK supported (enough for large projects
though) JSON is not as natural as in JS, parsing is clunky 13. GWT
VS ? 14. GWT ARCHITECTURE OVERVIEW 15. Building User Interface 16.
GWT USER INTERFACE GWT user interface classes are similar to
thosein existing UI frameworks such as Swing andSWT.GWT widgets are
rendered using dynamically-created HTMLrather than pixel-oriented
graphics The Widget classes make it easier toquickly build
interfaces that will workcorrectly on all browsers. 17. WIDGETS
LIBRARY 18. WIDGETS LIBRARY 19. WIDGETS LIBRARY 20. WIDGETS LIBRARY
21. EVENT HANDLER Events in GWT use the handler modelsimilar to
other user interface frameworksA handler interface defines one or
more methods that thewidget calls to announce an eventA class
wishing to receive events of a particular typeimplements the
associated handler interface and then passesa reference to itself
to the widget to subscribe to a set ofevents. 22. EVENT HANDLER
Examplepublic void anonClickHandlerExample() {Button b = new
Button("Click Me");b.addClickHandler(new ClickHandler() { public
void onClick(ClickEvent event) {// handle the click event }});} 23.
APPLY STYLES GWT applications use CSS for visualstyling Update
styles dynamically in Java code Associate style sheets with the
projectUsing a tag in the host HTML page.Using the element in the
module XML file 24. Client-Side RPC Architecture 25. GWT REMOTE
PROCEDURE CALL Mechanism for interacting with server by invoking
amethod Ex: fetching data from server GWT RPC makes it easy for the
client and server topass Java objects back and forth over HTTP
provides serialization mechanism to bridge between client and
server Any object that needs to send is a GWT Serialization type
Proper use of GWT RPC can allow you to develop anapplication where
all the UI logic resides on the client,leaving business logic on
the server) Resulting in an application with greatly improved
performance, reduced bandwidth, and reduced web server load 26.
GWT-RPC DIAGRAM Calls greetingService.greetserver(Ron)Browser
Client-side code serializes objects and generatesRPC request
payload RPC Request is sent to the server POST /sample HTTP/1.1
..snip.. 5|0|6|http://gwtsite/sample/|29F 4EA1240F157649C12466F01
F46F60|com.test.client.Greetin gService|greetServer|java.lang
.String|myInput|1|2|3|4|1|5|6| GWT Service 27. GWT-RPC DIAGRAM
BrowserHTTP/1.1 200 OK..snip..//OK[1,["Hello, Ron!
I amrunning jetty-6.1.x.
Itlooks like you are using:
Chrome/6.0.472.63"],0,5] Parses and deserializes the request
payload Executes the greetingServer method Sends JSON serialized
response to the client GWT Service 28. GWT RPC PLUMBING
ARCHITECTURE 29. IMPLEMENTING GWT RPC Define an interface for your
service that extendsRemoteService and lists all RPC method called
Synchronous Interface Implement the service at server-sideThis
class extends RemoteServiceServlet and implement the
createdinterface Define an asynchronous interface to your service
to becalled from the client-side code Based on original service
interface Require caller to pass callback object that can be
notified when async call completes. 30. SERIALIZABLE TYPES GWT RPC
method parameters and return types must beserializableThese values
will be transmitted across network between client andserver Java
data types are already serializablePrimitive, such as char, byte,
short, int, long, boolean, float, or double.String, Date or
primitive wrapper: Character, Integer, Byte, Double,Array of
serializable typesSerializable user-defined class 31. HANDLING
EXCEPTION Making RPCs opens up the possibility of a varietyof
errorsNetworks fail, servers crash, and problems occur
whileprocessing a server call GWT lets you handle these conditions
in terms of Javaexceptions Caller should
implementAsyncCallBack.onFailure(Throwable) to handle exception 32.
Create, develop, execute anddeploy GWT Applications 33. History
management 34. GWT HISTORY MECHANISMGWT applications use history
token to help Ajaxdeveloper activate browser history The token will
be saved in browser history as a URL fragment Ex:
http://www.example.com/historyexample/HistoryExample.html#page 1To
enable history to your Ajax Add a history token to the history
stack when you want to enable history event Create an object that
implements the ValueChangeHandler interface, parses new token and
changes the application state to match 35. Internationalization 36.
INTERNATIONALIZATIONGWT offers multiple internationalization
techniques Static String Internationalization Dynamic String
InternationalizationStatic String Internationalization Extends
Constants Interface Extends Message Interface Use properties
filesDynamic String Internationalization 37. JUnit Testing 38.
JUNIT TESTING GWT provides integration with the popular JUnit unit
testing framework GWT allows JUnit test cases to run in either
development mode or production mode. 39. Javascript Native
Interface (JSNI) 40. WHY JSNI?Sometimes its very useful to mix
handwritten Javascript to Javasource code Ex: access low-level
browser functionality not exposed by the GWT APIYou can use JSNI
to: Implement a Java method directly in JavaScript Wrap type-safe
Java method signatures around existing JavaScript Call from
JavaScript code into Java code and vice-versa Throw exceptions
across Java/JavaScript boundaries Read and write Java fields from
JavaScript Use development mode to debug both Java source (with a
Java debugger) and JavaScript (with a script debugger) 41.
RESOURCEShttp://code.google.com/webtoolkit/ Main site for
GWThttp://googlewebtoolkit.blogspot.com/http://developerlife.com
42. Question & Answer