google web toolkit: an introduction
Post on 15-May-2015
591 Views
Preview:
TRANSCRIPT
Copyright © Clarity Training, Inc. 2008-2009
Google Web Toolkit: An Introduction
David GearyPresidentClarity Training, Inc. clarity.training@gmail.com
Copyright © Clarity Training, Inc. 2008-2009
JSF
David Geary
Copyright © Clarity Training, Inc. 2008-2009
What GWT is How to get started quickly with GWT How to implement I18N, using CSS How to implement server side services How to integrate JavaScript
In this session, you will learn
Copyright © Clarity Training, Inc. 2008-2009
Introduction Implementing applications API overview: widgets on the client On the server: services Integrating JavaScript
Agenda
Copyright © Clarity Training, Inc. 2008-2009
Old problems, new solutions
Copyright © Clarity Training, Inc. 2008-2009
Code for this talk is from...
coolandusefulgwt.com
Copyright © Clarity Training, Inc. 2008-2009
Ajax is hard• It requires:
expertise in JavaScript a mixture of disparate technologies integration of client- and server-code
Ajax libraries make things easier, but...
The premise
Copyright © Clarity Training, Inc. 2008-2009
You can develop Ajax-enabled web apps in Java• Implement client-side UI in pure Java• Very little knowledge of JavaScript required• Familiar idioms from the AWT and Swing
The promise
Copyright © Clarity Training, Inc. 2008-2009
Application generator for a quick startConvention over configurationInstant turnaround after changesNon-Ajax AjaxAwesome productivity
Top 5 features
Copyright © Clarity Training, Inc. 2008-2009
GWT is not for everyone. Here’s the sweet spot:• Swing-like apps that run in a browser• Java developers who’ve used a desktop ui framework, or at least a
component-based framework like JSF
The GWT sweet spot
Copyright © Clarity Training, Inc. 2008-2009
Introduction Implementing applications API overview: widgets on the client On the server: services Integrating JavaScript
Agenda
Copyright © Clarity Training, Inc. 2008-2009
You implement user interfaces in pure Java• Albeit, with a limited subset of Java• Selected choices from java.lang and java.util
In Hosted mode, your code runs in the JVM• Use your favorite Java debugger
In Web mode: JavaScript runs in the browser• GWT compiles Java to JavaScript
Client-side code
Copyright © Clarity Training, Inc. 2008-2009
Server-side code is written in Java• All of Java is available• Code is compiled normally
Server-side code is packaged in services• Remote procedure calls from client-server• Services are accessed with a remote servlet
Server-side code
Copyright © Clarity Training, Inc. 2008-2009
Project generator (Eclipse) Application generator I18N generator Test generator
Get started quickly
Copyright © Clarity Training, Inc. 2008-2009
Demonstration
Copyright © Clarity Training, Inc. 2008-2009
Introduction Implementing applications API overview: widgets on the client On the server: services Integrating JavaScript
Agenda
Copyright © Clarity Training, Inc. 2008-2009
Widget hierarchy (partial)
Copyright © Clarity Training, Inc. 2008-2009
The basic widgets• Label, Image, TextBox, Button, Hyperlink• FileUpload, Tree, TabPanel, Popup, FlexTable
Panels• HorizontalPanel and VerticalPanel
Listeners• ClickListener, MouseListener, FocusListener, ...
Commonly used widgets
Copyright © Clarity Training, Inc. 2008-2009
Demonstration
Copyright © Clarity Training, Inc. 2008-2009
Introduction Implementing applications API overview: widgets on the client On the server: services Integrating JavaScript
Agenda
Copyright © Clarity Training, Inc. 2008-2009
� Two interfaces:• Remote interface• Asynchronous interface
� One class:• Remote servlet class
Invoking server-side code
Copyright © Clarity Training, Inc. 2008-2009
Remote and Asynch interfaces
public interface WeatherService extends RemoteService { public String getWeatherForZip(String zip, boolean isCelsius);}
public interface WeatherServiceAsync { public void getWeatherForZip(String zip, boolean isCelsius, AsyncCallback callback);}
Copyright © Clarity Training, Inc. 2008-2009
The servlet
public class WeatherServiceImpl extends RemoteServiceServlet implements WeatherService {
public String getWeatherForZip(String zip, boolean isCelsius) { // invoke Yahoo! weather web service }}
<servlet path=”/weatherService” class=”example.server.WeatherServiceImpl”/>
Copyright © Clarity Training, Inc. 2008-2009
Creating the weather service
// Get a reference to the service... WeatherServiceAsync service = (WeatherServiceAsync) GWT.create(WeatherService.class);
// Set the entry point for the service...((ServiceDefTarget)service).setServiceEntryPoint (GWT.getModuleBaseURL() + “/weatherService”);
...
Copyright © Clarity Training, Inc. 2008-2009
Using the weather service
...
// Invoke the service with an asynchronous callback service.getWeatherForZip("80132", true, new AsyncCallback() { public void onSuccess(Object result) { displayHTML(result); } public void onFailure(Throwable t) { showAlert("Remote service call failed: " + t.getMessage()); } });
Copyright © Clarity Training, Inc. 2008-2009
Demonstration
Copyright © Clarity Training, Inc. 2008-2009
Introduction Implementing applications API overview: widgets on the client On the server: services Integrating JavaScript
Agenda
Copyright © Clarity Training, Inc. 2008-2009
Integrating Script.aculo.us effects
public class MyApp implements EntryPoint { ... public void onModuleLoad() { Label errorMessage = new Label(”Get it together!”); ... errorMessage.setVisible(false); ... applyEffect(”Shake”, errorMessage.getElement()); } ... private native void applyEffect(String effect, Element e) /*-{ $wnd.Effect[effect](e); }-*/; ...}
Copyright © Clarity Training, Inc. 2008-2009
Demonstration
Copyright © Clarity Training, Inc. 2008-2009
Questions
top related