SlideShare a Scribd company logo
GWT 2 = Easier AJAXYaJUG11/5/2010
Who am I?Olivier GérardinTechnical Director, Sfeir Benelux (groupe Sfeir)Java / Web architect13+ years Java3 years GWT
AgendaGWT remindersNew in GWT 2.0SpeedTracerIn-browser development modeCode splitting & compile reportUiBinderClient bundleLayout panelsMisc.Pointers, Conclusion, Q&A
Reminders
GWT solves all your problemsGWT gives you AJAX without the pain of JavaScript developmentTakes care of cross-browser issuesAllows full debugging (breakpoints, step by step, inspecting/watching variables)Strong static typing early error detectionFull refactoring optionsNo browser plugin or mandatory IDEShort learning curveSimple RPC mechanism built inBut can communicate with any server technology
Program in Java…GWT allows developing client-side web apps in full Java (with only a few restrictions)Leverage existing Java tools and skillsUse any IDE (Eclipse, NetBeans, IntelliJ, …)Program like a traditional graphical client (Swing, SWT, …)Widgets, containers, listeners, etc.Use OO patterns (MVC, MVP, observer, composite, etc.)Test like any Java appUse standard Java debuggersTest with JUnit
… deploy in JavaScriptJavaScript is only generated:For deploymentTo test in actual web modeGWT guarantees that the generated JavaScript app behaves exactly like the Java app And it does (most of the time)
4 easy piecesJava-to-JavaScript compilerGenerates JS code from Java sourcePerforms many optimizationJRE emulation libraryGWT compatible version of most used Java core classes (java.lan, java.util)Java librariesUtility classes (JSON, I18N, …)Widget libraryHosted Development modeRun/debug the app as Java bytecode
Key benefits
Easy developmentDuring development, you are writing and running a classic Java appUse your favorite IDEAll IDE features available (code completion, code analysis, refactoring, links, Javadoc, …)Plugins help GWT-specific taskslaunching development modecompilingrefactoringcreating projects, modules, RPC services, …even design GUI (GWT Designer from Instantiations)
More benefitsEasy RPC implementation / consumption / deploymentEasy JSON / XML parsingEasy UI building / widget reuseEasy history supportEasy i18nEasy debugging Easy testing
Any room for improvement???Of course…
New in GWT 2.0
Speed tracerPerformance analysis toolVisualize where your app spends time:JS executionBrowser renderingCSS handling (style selection/calculation)DOM handling / event processingResource loading
Speed Tracer: example
In-browser development modeBefore 2.0: hosted mode uses customized browser engineHeavily customizedOnly one supported browser per platform (IE on Windows, WebKit on Mac, Mozilla on Linux)Difficult to keep up-to-dateIncludes platform-specific code (SWT)Browser and hosted application share the same processMost plugins don’t work (including Google Gears…)
In-browser development modenow:Hosted mode shell runs outside browserCommunicates with browser using plugin through TCP
In-browser development modeBenefitsUse any (supported) browser/version on any platformCurrently Safari, Firefox, IE, Chrome (not on OS X!)Behavior closer to web modeNo interference with browser pluginsNo more platform-specific stuff in GWT (one jar for all!)Network protocol between shell and browser  cross-platform dev possibleDev mode shell on machine X, slave browser on machine YE.g. dev on Linux, test in IE on Windows…
Initiating dev mode
Plugin installation
Code splittingBefore: monolithic download can become very bigSlow startup timesAfter: Programmer can insert “split points” in codeHints for the compiler to place everything not required up to split point in separate downloadCompiler divides code in several “chunks”, which are loaded on-demandBenefits:Initial loading time reduced 50% on average with a single split pointAllows on-demand module loading (provider pattern)
Specifying a split pointGWT.runAsync(newRunAsyncCallback() {publicvoidonFailure(Throwable reason) {// …		}		public void onSuccess() {// ..}	});
Pattern: AsyncProviderpublicinterfaceAsyncClient<P> {	voidonUnavailable(Throwable reason);	void onAvailable(P instance);}
Async provider: Implementing the providerpublicclass Provider {privatestatic Provider instance = null;public static void getAsync(finalAsyncClient<Provider> client) {GWT.runAsync(newRunAsyncCallback() {			public void onFailure(Throwable reason) {client.onUnavailable(reason);			}			public void onSuccess() {			if (instance == null) {instance = new Provider();				}client.onAvailable(instance);			}	});	}
Async provider: Loading the providerprivatevoidloadProvider() {Provider.getAsync(newAsyncClient<Provider>() {		publicvoidonAvailable(Provider provider) {provider.doSomething();		}		publicvoidonUnavailable(Throwable reason) {Window.alert(”Failed: " + reason);		}	});}
Compile Report (formerly: SOYC)Better understanding of the compilation processHelps tuning code splittingSimple compiler flagProduces HTML reportShows:PermutationsSizes per chunk, package, etc.DependenciesCompiler flag: -compileReport
Compile Report: output
Declarative UI: UiBinderDeclarative construction of GUI using XML grammarMix HTML and widgetsBenefits:Clearly separate responsibilities  better collaborationStatic UI construction (XML)Dynamic UI behavior (Java)More efficientHTML vs DOM API callsEasy to transition from static HTML to dynamic
UiBinder: define layoutXML file (xx.ui.xml)<ui:UiBinderxmlns:ui='urn:ui:com.google.gwt.uibinder'xmlns:gwt='urn:import:com.google.gwt.user.client.ui'>		<gwt:HorizontalPanel>			<gwt:Labeltext="Sexe :" />			<gwt:VerticalPanel>			<gwt:RadioButtonname='sexeradio' text='M’ />			<gwt:RadioButtonname='sexeradio' text='F’ />		</gwt:VerticalPanel>	</gwt:HorizontalPanel></ui:UiBinder>
UiBinder: instantiatepublicclass SexeRadio2 extends Composite {@UiTemplate("SexeRadio2.ui.xml")interfaceMyUiBinderextendsUiBinder<Panel, SexeRadio2> {}privatestaticfinalMyUiBinderbinder = GWT.create(MyUiBinder.class);public SexeRadio2() {	finalPanel panel =binder.createAndBindUi(this);initWidget(panel);}
UiBinder: bind fieldsAutomatically assign references to dynamically created widgets to designated Java fields (@UiField)XML :<gwt:RadioButtonname='sexeradio' text='M’ ui:field='maleRadio' /><gwt:RadioButtonname='sexeradio' text='F’ ui:field='femaleRadio'/>Code: @UiFieldRadioButtonmaleRadio;@UiFieldRadioButtonfemaleRadio;
UiBinder: bind handlersAutomatically attach event handlers (@UiHandler)Widgets only (not DOM elements)Handler type inferred from parameter typeCode:@UiHandler("maleRadio")voidmaleClicked(ClickEvent event) {GWT.log("C'est un garçon!", null);}
More UiBinder goodnessMix HTML and widgets in same XML fileDefine CSS styles with <ui:style>Inline / externalApply to widgets with attributes styleNames / addStyleNamesProgrammatic access to styles (works with CssResource)Use external resources (images, CSS stylesheets, …) declared as client bundles with <ui:with>Instantiate widgets that don’t have zero-arg constructor with @UiFactory
Resource bundlesDownload multiple heterogeneous resources from server in a single requestImages (similar to ImageBundle in 1.x)CSSTextAny other resourceBenefits:Fewer round trips to the serverLess overheadMore responsive interface
Resource bundles: general mechanismFamiliar mechanismCoding time: define interfaceMethod type constrains resource typeMethod name (accessor) designates resourceAnnotation @source specifies resource contentIf unspecified, source is derived from accessorI18N aware (append _fr, _fr_FR)Runtime: access resourceObtain instance via GWT.create(interface.class) and call accessor directlyReference accessor through other mechanism (CSS injection @sprite, etc.)
Resource bundles: DataResourceWorks with any kind of sourceMake the resource available through a URLRename file to make resulting URL strongly-cacheable if appropriateXXX.pdf AAA12345.cache.pdfWebserver should be configured accordingly
Resource bundles: TextResourceAccess to static text contentTextResource is inlined into JavaScriptExternalTextResource is fetched asynchronouslyinterface Resources extendsClientBundle {    Resources INSTANCE = GWT.create(Resources.class);@Source(“text1.txt")TextResource text1();@Source(“text2.txt")ExternalTextResource text2();}
Accessing TextResouce// TextResourcemyTextArea.setInnerText(		Resources.INSTANCE.text1().getText());//ExternalTextResource  Resources.INSTANCE.text2().getText(newResourceCallback<TextResource>() {publicvoidonError(ResourceExceptione) 			{ ... }publicvoidonSuccess(TextResourcer) {myTextArea.setInnerText(r.getText()); 		}  });
Resource bundles: ImageResourceOptimize runtime access to image dataTransparently group /split imagesUses ImageIO libraryUse in injected CSS with @sprite directive Supports most image formatsIncluding animated GIFNot an image-processing library!
Resource bundles: CssResourceDefine an extension of CSSSyntax validations / compile-time optimizationsInjected at runtime	Usage:Write CSS stylesheetExtend CssResource	interfaceMyCssextendsCssResource {	}Include in ClientBundleinterfaceMyResourcesextendsClientBundle {@Source("my.css")MyCsscss();}Use GWT.create(MyResources.class) to obtain instance of bundleCall CssResource.ensureInjected() to inject stylesheet in page
CSS extensionsSprites with @spriteBundle:classMyResourcesextendsClientBundle {@Source("my.css")MyCssResourcecss();@Source("some.png")ImageResourceimageAccessor();}my.css:@sprite .mySpriteClass{ gwt-image: "imageAccessor” 		}
CSS extensionsConstants with @defRuntime evaluation with @eval and value()Conditional CSS with @if/@elif/@else
Layout panelsLayout panelsPredictable, consistent layoutConstraint based system built on top of CSSPlays nice with custom CSS stylesEach child must have 0 or 2 constraints per axisHorizontal: none, left/width, right/width, left/rightVertical: none, top/height, bottom/height, top/bottomno constraint = fill parentAny unit (%, px, …)Must be added to an instance of ProvidesResizetypically RootLayoutPanel
Layout PanelsEasily usable with UiBinder<g:layer left=‘25% right=‘25%’ top=‘10px’ bottom=‘0’><g:Label>Label</g:Label></g:layer>Bunch of specialized panels implemented as LayoutPanels:DockLayoutPanel, SplitLayoutPanel, StackLayoutPanel, TabLayoutPanel
And also…Compiler optimizationsMost notably reduces generated JS size (expect 3-20 %)Draft compile mode: flag  -drafCompileNo optimizations / Faster buildsNot for deployment!GWTTestCaseNo more dependency on SWTNo native code / browser requiredHtmlUnit: GUI-less browser written in Java
Pointers, Conclusion, etc.
PointersGWT home (downloads, docs, FAQs, guides, etc.)http://code.google.com/toolkitGoogle groups “GWT” grouphttp://groups.google.com/group/Google-Web-ToolkitonGWT: fresh news about GWThttp://www.ongwt.comLinkedIn “GWT Users” grouphttp://www.linkedin.com/groups?gid=129889
Shameless self-promotion
Thank youQuestions?gerardin.o@sfeir.lublog.gerardin.infotwitter: @ogerardin

More Related Content

PDF
Integration tests: use the containers, Luke!
Roberto Franchini
 
PDF
OrientDB - The 2nd generation of (multi-model) NoSQL
Roberto Franchini
 
PDF
drmaatutggf12
tutorialsruby
 
PPTX
Qt test framework
ICS
 
PDF
Devfest09 Cschalk Gwt
Chris Schalk
 
ODP
GWT 2 Is Smarter Than You
Robert Cooper
 
PDF
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
ekino
 
PPTX
Step by step guide to create theme for liferay dxp 7
Azilen Technologies Pvt. Ltd.
 
Integration tests: use the containers, Luke!
Roberto Franchini
 
OrientDB - The 2nd generation of (multi-model) NoSQL
Roberto Franchini
 
drmaatutggf12
tutorialsruby
 
Qt test framework
ICS
 
Devfest09 Cschalk Gwt
Chris Schalk
 
GWT 2 Is Smarter Than You
Robert Cooper
 
Se lancer dans l'aventure microservices avec Spring Cloud - Julien Roy
ekino
 
Step by step guide to create theme for liferay dxp 7
Azilen Technologies Pvt. Ltd.
 

What's hot (20)

ODP
Spring 4 advanced final_xtr_presentation
sourabh aggarwal
 
PDF
How to build to do app using vue composition api and vuex 4 with typescript
Katy Slemon
 
PDF
Qt for Python
ICS
 
PDF
Best Practices in Qt Quick/QML - Part 2
Janel Heilbrunn
 
PDF
netbeans
tutorialsruby
 
PDF
In the Brain of Hans Dockter: Gradle
Skills Matter
 
PPTX
Kubernetes #4 volume &amp; stateful set
Terry Cho
 
PPTX
Best Practices in Qt Quick/QML - Part I
ICS
 
PDF
OSGi Blueprint Services
Guillaume Nodet
 
PPTX
Microservices/dropwizard
FKM Naimul Huda, PMP
 
PDF
Best Practices in Qt Quick/QML - Part III
ICS
 
PDF
Best Practices in Qt Quick/QML - Part 3
ICS
 
PDF
Drools & jBPM Workshop London 2013
Mauricio (Salaboy) Salatino
 
PDF
Intro to Web Components, Polymer & Vaadin Elements
Manuel Carrasco Moñino
 
PDF
Java EE 01-Servlets and Containers
Fernando Gil
 
PDF
Communication in Node.js
Edureka!
 
PPT
Lecture 2
Ahmed Madkor
 
PPTX
Vertx daitan
Claudio Eduardo de Oliveira
 
PDF
Security DevOps - Wie Sie in agilen Projekten trotzdem sicher bleiben // DevO...
Christian Schneider
 
PPTX
NTT SIC marketplace slide deck at Tokyo Summit
Toshikazu Ichikawa
 
Spring 4 advanced final_xtr_presentation
sourabh aggarwal
 
How to build to do app using vue composition api and vuex 4 with typescript
Katy Slemon
 
Qt for Python
ICS
 
Best Practices in Qt Quick/QML - Part 2
Janel Heilbrunn
 
netbeans
tutorialsruby
 
In the Brain of Hans Dockter: Gradle
Skills Matter
 
Kubernetes #4 volume &amp; stateful set
Terry Cho
 
Best Practices in Qt Quick/QML - Part I
ICS
 
OSGi Blueprint Services
Guillaume Nodet
 
Microservices/dropwizard
FKM Naimul Huda, PMP
 
Best Practices in Qt Quick/QML - Part III
ICS
 
Best Practices in Qt Quick/QML - Part 3
ICS
 
Drools & jBPM Workshop London 2013
Mauricio (Salaboy) Salatino
 
Intro to Web Components, Polymer & Vaadin Elements
Manuel Carrasco Moñino
 
Java EE 01-Servlets and Containers
Fernando Gil
 
Communication in Node.js
Edureka!
 
Lecture 2
Ahmed Madkor
 
Security DevOps - Wie Sie in agilen Projekten trotzdem sicher bleiben // DevO...
Christian Schneider
 
NTT SIC marketplace slide deck at Tokyo Summit
Toshikazu Ichikawa
 
Ad

Similar to YaJUG: What's new in GWT2 (20)

PPT
GWT is Smarter Than You
Robert Cooper
 
PPTX
GWT = easy AJAX
Olivier Gérardin
 
PPT
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
Fred Sauer
 
PPT
GWT
Lorraine JUG
 
PPT
GWT Introduction for Eclipse Day
DNG Consulting
 
PDF
T 0230 Google Wave Powered By Gwt
supertoy2015
 
PDF
GWT - Building Rich Internet Applications Using OO Tools
barciszewski
 
PPT
Google Web Toolkits
Yiguang Hu
 
PPT
Google Web Toolkit Introduction - eXo Platform SEA
nerazz08
 
PDF
Javascript as a target language - GWT KickOff - Part 2/2
JooinK
 
PPT
Introduction to Google Web Toolkit
Didier Girard
 
PPT
GWT Extreme!
cromwellian
 
PPTX
Gwt overview & getting started
Binh Bui
 
PPT
Gwtcreatekeynote
Ray Cromwell
 
PPT
Google Dev Day2007
lucclaes
 
PDF
Gwt.Create Keynote San Francisco
Ray Cromwell
 
PPT
GWT Training - Session 1/3
Faiz Bashir
 
PPT
Gwt Presentation1
rajakumar.tu
 
PDF
Gwt kickoff - Alberto Mancini & Francesca Tosi
firenze-gtug
 
PPTX
Gwt session
Mans Jug
 
GWT is Smarter Than You
Robert Cooper
 
GWT = easy AJAX
Olivier Gérardin
 
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
Fred Sauer
 
GWT Introduction for Eclipse Day
DNG Consulting
 
T 0230 Google Wave Powered By Gwt
supertoy2015
 
GWT - Building Rich Internet Applications Using OO Tools
barciszewski
 
Google Web Toolkits
Yiguang Hu
 
Google Web Toolkit Introduction - eXo Platform SEA
nerazz08
 
Javascript as a target language - GWT KickOff - Part 2/2
JooinK
 
Introduction to Google Web Toolkit
Didier Girard
 
GWT Extreme!
cromwellian
 
Gwt overview & getting started
Binh Bui
 
Gwtcreatekeynote
Ray Cromwell
 
Google Dev Day2007
lucclaes
 
Gwt.Create Keynote San Francisco
Ray Cromwell
 
GWT Training - Session 1/3
Faiz Bashir
 
Gwt Presentation1
rajakumar.tu
 
Gwt kickoff - Alberto Mancini & Francesca Tosi
firenze-gtug
 
Gwt session
Mans Jug
 
Ad

Recently uploaded (20)

PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Software Development Methodologies in 2025
KodekX
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
The Future of AI & Machine Learning.pptx
pritsen4700
 

YaJUG: What's new in GWT2

  • 1. GWT 2 = Easier AJAXYaJUG11/5/2010
  • 2. Who am I?Olivier GérardinTechnical Director, Sfeir Benelux (groupe Sfeir)Java / Web architect13+ years Java3 years GWT
  • 3. AgendaGWT remindersNew in GWT 2.0SpeedTracerIn-browser development modeCode splitting & compile reportUiBinderClient bundleLayout panelsMisc.Pointers, Conclusion, Q&A
  • 5. GWT solves all your problemsGWT gives you AJAX without the pain of JavaScript developmentTakes care of cross-browser issuesAllows full debugging (breakpoints, step by step, inspecting/watching variables)Strong static typing early error detectionFull refactoring optionsNo browser plugin or mandatory IDEShort learning curveSimple RPC mechanism built inBut can communicate with any server technology
  • 6. Program in Java…GWT allows developing client-side web apps in full Java (with only a few restrictions)Leverage existing Java tools and skillsUse any IDE (Eclipse, NetBeans, IntelliJ, …)Program like a traditional graphical client (Swing, SWT, …)Widgets, containers, listeners, etc.Use OO patterns (MVC, MVP, observer, composite, etc.)Test like any Java appUse standard Java debuggersTest with JUnit
  • 7. … deploy in JavaScriptJavaScript is only generated:For deploymentTo test in actual web modeGWT guarantees that the generated JavaScript app behaves exactly like the Java app And it does (most of the time)
  • 8. 4 easy piecesJava-to-JavaScript compilerGenerates JS code from Java sourcePerforms many optimizationJRE emulation libraryGWT compatible version of most used Java core classes (java.lan, java.util)Java librariesUtility classes (JSON, I18N, …)Widget libraryHosted Development modeRun/debug the app as Java bytecode
  • 10. Easy developmentDuring development, you are writing and running a classic Java appUse your favorite IDEAll IDE features available (code completion, code analysis, refactoring, links, Javadoc, …)Plugins help GWT-specific taskslaunching development modecompilingrefactoringcreating projects, modules, RPC services, …even design GUI (GWT Designer from Instantiations)
  • 11. More benefitsEasy RPC implementation / consumption / deploymentEasy JSON / XML parsingEasy UI building / widget reuseEasy history supportEasy i18nEasy debugging Easy testing
  • 12. Any room for improvement???Of course…
  • 14. Speed tracerPerformance analysis toolVisualize where your app spends time:JS executionBrowser renderingCSS handling (style selection/calculation)DOM handling / event processingResource loading
  • 16. In-browser development modeBefore 2.0: hosted mode uses customized browser engineHeavily customizedOnly one supported browser per platform (IE on Windows, WebKit on Mac, Mozilla on Linux)Difficult to keep up-to-dateIncludes platform-specific code (SWT)Browser and hosted application share the same processMost plugins don’t work (including Google Gears…)
  • 17. In-browser development modenow:Hosted mode shell runs outside browserCommunicates with browser using plugin through TCP
  • 18. In-browser development modeBenefitsUse any (supported) browser/version on any platformCurrently Safari, Firefox, IE, Chrome (not on OS X!)Behavior closer to web modeNo interference with browser pluginsNo more platform-specific stuff in GWT (one jar for all!)Network protocol between shell and browser  cross-platform dev possibleDev mode shell on machine X, slave browser on machine YE.g. dev on Linux, test in IE on Windows…
  • 21. Code splittingBefore: monolithic download can become very bigSlow startup timesAfter: Programmer can insert “split points” in codeHints for the compiler to place everything not required up to split point in separate downloadCompiler divides code in several “chunks”, which are loaded on-demandBenefits:Initial loading time reduced 50% on average with a single split pointAllows on-demand module loading (provider pattern)
  • 22. Specifying a split pointGWT.runAsync(newRunAsyncCallback() {publicvoidonFailure(Throwable reason) {// … } public void onSuccess() {// ..} });
  • 24. Async provider: Implementing the providerpublicclass Provider {privatestatic Provider instance = null;public static void getAsync(finalAsyncClient<Provider> client) {GWT.runAsync(newRunAsyncCallback() { public void onFailure(Throwable reason) {client.onUnavailable(reason); } public void onSuccess() { if (instance == null) {instance = new Provider(); }client.onAvailable(instance); } }); }
  • 25. Async provider: Loading the providerprivatevoidloadProvider() {Provider.getAsync(newAsyncClient<Provider>() { publicvoidonAvailable(Provider provider) {provider.doSomething(); } publicvoidonUnavailable(Throwable reason) {Window.alert(”Failed: " + reason); } });}
  • 26. Compile Report (formerly: SOYC)Better understanding of the compilation processHelps tuning code splittingSimple compiler flagProduces HTML reportShows:PermutationsSizes per chunk, package, etc.DependenciesCompiler flag: -compileReport
  • 28. Declarative UI: UiBinderDeclarative construction of GUI using XML grammarMix HTML and widgetsBenefits:Clearly separate responsibilities  better collaborationStatic UI construction (XML)Dynamic UI behavior (Java)More efficientHTML vs DOM API callsEasy to transition from static HTML to dynamic
  • 29. UiBinder: define layoutXML file (xx.ui.xml)<ui:UiBinderxmlns:ui='urn:ui:com.google.gwt.uibinder'xmlns:gwt='urn:import:com.google.gwt.user.client.ui'> <gwt:HorizontalPanel> <gwt:Labeltext="Sexe :" /> <gwt:VerticalPanel> <gwt:RadioButtonname='sexeradio' text='M’ /> <gwt:RadioButtonname='sexeradio' text='F’ /> </gwt:VerticalPanel> </gwt:HorizontalPanel></ui:UiBinder>
  • 30. UiBinder: instantiatepublicclass SexeRadio2 extends Composite {@UiTemplate("SexeRadio2.ui.xml")interfaceMyUiBinderextendsUiBinder<Panel, SexeRadio2> {}privatestaticfinalMyUiBinderbinder = GWT.create(MyUiBinder.class);public SexeRadio2() { finalPanel panel =binder.createAndBindUi(this);initWidget(panel);}
  • 31. UiBinder: bind fieldsAutomatically assign references to dynamically created widgets to designated Java fields (@UiField)XML :<gwt:RadioButtonname='sexeradio' text='M’ ui:field='maleRadio' /><gwt:RadioButtonname='sexeradio' text='F’ ui:field='femaleRadio'/>Code: @UiFieldRadioButtonmaleRadio;@UiFieldRadioButtonfemaleRadio;
  • 32. UiBinder: bind handlersAutomatically attach event handlers (@UiHandler)Widgets only (not DOM elements)Handler type inferred from parameter typeCode:@UiHandler("maleRadio")voidmaleClicked(ClickEvent event) {GWT.log("C'est un garçon!", null);}
  • 33. More UiBinder goodnessMix HTML and widgets in same XML fileDefine CSS styles with <ui:style>Inline / externalApply to widgets with attributes styleNames / addStyleNamesProgrammatic access to styles (works with CssResource)Use external resources (images, CSS stylesheets, …) declared as client bundles with <ui:with>Instantiate widgets that don’t have zero-arg constructor with @UiFactory
  • 34. Resource bundlesDownload multiple heterogeneous resources from server in a single requestImages (similar to ImageBundle in 1.x)CSSTextAny other resourceBenefits:Fewer round trips to the serverLess overheadMore responsive interface
  • 35. Resource bundles: general mechanismFamiliar mechanismCoding time: define interfaceMethod type constrains resource typeMethod name (accessor) designates resourceAnnotation @source specifies resource contentIf unspecified, source is derived from accessorI18N aware (append _fr, _fr_FR)Runtime: access resourceObtain instance via GWT.create(interface.class) and call accessor directlyReference accessor through other mechanism (CSS injection @sprite, etc.)
  • 36. Resource bundles: DataResourceWorks with any kind of sourceMake the resource available through a URLRename file to make resulting URL strongly-cacheable if appropriateXXX.pdf AAA12345.cache.pdfWebserver should be configured accordingly
  • 37. Resource bundles: TextResourceAccess to static text contentTextResource is inlined into JavaScriptExternalTextResource is fetched asynchronouslyinterface Resources extendsClientBundle { Resources INSTANCE = GWT.create(Resources.class);@Source(“text1.txt")TextResource text1();@Source(“text2.txt")ExternalTextResource text2();}
  • 38. Accessing TextResouce// TextResourcemyTextArea.setInnerText( Resources.INSTANCE.text1().getText());//ExternalTextResource Resources.INSTANCE.text2().getText(newResourceCallback<TextResource>() {publicvoidonError(ResourceExceptione) { ... }publicvoidonSuccess(TextResourcer) {myTextArea.setInnerText(r.getText()); } });
  • 39. Resource bundles: ImageResourceOptimize runtime access to image dataTransparently group /split imagesUses ImageIO libraryUse in injected CSS with @sprite directive Supports most image formatsIncluding animated GIFNot an image-processing library!
  • 40. Resource bundles: CssResourceDefine an extension of CSSSyntax validations / compile-time optimizationsInjected at runtime Usage:Write CSS stylesheetExtend CssResource interfaceMyCssextendsCssResource { }Include in ClientBundleinterfaceMyResourcesextendsClientBundle {@Source("my.css")MyCsscss();}Use GWT.create(MyResources.class) to obtain instance of bundleCall CssResource.ensureInjected() to inject stylesheet in page
  • 41. CSS extensionsSprites with @spriteBundle:classMyResourcesextendsClientBundle {@Source("my.css")MyCssResourcecss();@Source("some.png")ImageResourceimageAccessor();}my.css:@sprite .mySpriteClass{ gwt-image: "imageAccessor” }
  • 42. CSS extensionsConstants with @defRuntime evaluation with @eval and value()Conditional CSS with @if/@elif/@else
  • 43. Layout panelsLayout panelsPredictable, consistent layoutConstraint based system built on top of CSSPlays nice with custom CSS stylesEach child must have 0 or 2 constraints per axisHorizontal: none, left/width, right/width, left/rightVertical: none, top/height, bottom/height, top/bottomno constraint = fill parentAny unit (%, px, …)Must be added to an instance of ProvidesResizetypically RootLayoutPanel
  • 44. Layout PanelsEasily usable with UiBinder<g:layer left=‘25% right=‘25%’ top=‘10px’ bottom=‘0’><g:Label>Label</g:Label></g:layer>Bunch of specialized panels implemented as LayoutPanels:DockLayoutPanel, SplitLayoutPanel, StackLayoutPanel, TabLayoutPanel
  • 45. And also…Compiler optimizationsMost notably reduces generated JS size (expect 3-20 %)Draft compile mode: flag -drafCompileNo optimizations / Faster buildsNot for deployment!GWTTestCaseNo more dependency on SWTNo native code / browser requiredHtmlUnit: GUI-less browser written in Java
  • 47. PointersGWT home (downloads, docs, FAQs, guides, etc.)http://code.google.com/toolkitGoogle groups “GWT” grouphttp://groups.google.com/group/Google-Web-ToolkitonGWT: fresh news about GWThttp://www.ongwt.comLinkedIn “GWT Users” grouphttp://www.linkedin.com/groups?gid=129889