SlideShare a Scribd company logo
Js as a target language: 
GWT KickOff (Part 2/2) 
Alberto Mancini - alberto@jooink.com 
Francesca Tosi - francesca@jooink.com
Alberto Mancini 
alberto@jooink.com 
http://github.com/jooink 
http://www.jooink.com 
http://jooink.blogspot.com
Francesca Tosi 
francesca@jooink.com 
+FrancescaTosi 
@francescatosi 
http://github.com/jooink 
http://www.jooink.com 
http://jooink.blogspot.com
GWT 
GWT is a toolkit to develop Ajax web 
application with Java. 
The programmer writes Java code and this 
code is translated into HTML and Javascript via 
the GWT compiler. 
The compiler creates browser specific HTML 
and JavaScript to support all the major 
browsers correctly.
setup 
1. java sdk: http://www.java.com/it/download/ (e.g 1.7) 
2. eclipse: http://www.eclipse.org/downloads/ (e.g. EE) 
3. GWT Eclipse Plugin: 
https://developers.google.com/eclipse/docs/getting_started 
4. Create simple project 
5. run ‘dev mode’ 
6. open in browser http://127.0.0.1:8888/?get. 
condeserv=127.0.0.1:9997 
(install browser plugin)
GWT cont'd - Tools in the Toolkit 
+ GWTc, compiler Java to Javascript 
+ Emulated JRE 
+ Web UI class library (Widgets) 
+ Eclipse Plugin, SpeedTracer, Designer 
It's open source, completely free, and used by 
thousands of developers around the world (in 
Google AdWords,Orkut,Blogger,Groups)
Toolkit != Framework 
Frameworks that may help 
https://github.com/ArcBees/GWTP 
model-view-presenter framework 
http://www.jboss.org/errai 
CDI, and JPA for GWT 
http://www.tessell.org/ 
app framework (on gwt-pectin)
GWT cont'd - Developing & Running 
GWT provides two (3 actually) modes 
● Development Mode: allows to debug the 
Java code of your application directly via the 
standard Java debugger. 
● Web mode: the application is translated into 
HTML and Javascript code and can be 
deployed to a webserver. 
● SuperDevMode
GWT cont'd - Why ? 
Typed Language 
Well Known Programming Framework 
Optimize 
Browser Independence (quite, almost) 
+ 
'Native' through jsni 
Move Objects between client and server
GWT cont'd - History 
● GWT 1.0 (2006) 
● GWT 1.3 (2007) First Open Source Release, OSX support 
● GWT 1.4 (2007) JUnit and ImageBundle 
● GWT 1.5 (2008) Java 1.5 support, Overlay Types, DOM API, CSS 
Themes, Linkers 
● GWT 1.6 (2009) EventHandlers, EMMA Support, WAR support, 
Parallelized Builds 
● GWT 1.7 (2009) Newer browser support, IE8, GPE and AppEngine 
● GWT 2.0 (2009) DevMode, DraftCompile, UIBinder, LayoutPanel, 
CodeSplitter, ClientBundle, CssResource 
● GWT 2.1 (2010) RequestFactory, Editor Framework, Validation, MVP, Cell 
Widgets 
● GWT 2.2 (2011) GWT Designer, HTML5 support 
● GWT 2.3 (2011) Better AppEngine integration 
● GWT 2.4 (2011) Maven and RequestFactory enhancements 
● GWT 2.5 (2012) SuperDevMode, Elemental, UiRenderers, 
FragmentMerging, ClosureCompiler
GWT cont'd - History 
● GWT 2.5.1 (2013) - bugfixes and optimizations 
● GWT 2.6.0 (2014) - java 7 - IE10 - Internet Explorer cleanup: IE6/7 
● GWT 2.6.1 (2014) - working on Super Dev Mode 
Annual Vaadin “The Future of GWT Report” 
https://vaadin.com/gwt/report-2013 
What’s going on. 
SuperDevMode 
Java8 
JsInterop 
GSS
GWT cont'd - Open Source Project 
The GWT Steering committee was founded in 2012 to help 
the GWT project become an even bigger success as an 
open source project. 
● Ray Cromwell, Google 
● Artur Signell, Vaadin 
● Colin Alworth, Sencha 
● Mike Brock, RedHat 
● Thomas Broyer 
● Stephen Haberman, Bizo 
● Daniel Kurka, Google 
● Christian Goudreau, Arcbees 
● Konstantin Solomatov, Jetbrains
Anatomy 
Module html file 
Module xml file 
translatable directories
Modules 
Individual units of GWT configuration are called modules. A 
module bundles together all the configuration settings that a 
GWT project needs: 
● inherited modules 
● an entry point application class name; these are optional, 
although any module referred to in HTML must have at 
least one entry-point class specified 
● source path entries 
● public path entries 
● deferred binding rules, including property providers 
and class generators
Deferred Binding 
Deferred Binding is a feature of the GWT compiler that 
works by generating many versions of code at compile 
time, only one of which needs to be loaded by a particular 
client during bootstrapping at runtime. 
Each version is generated on a per browser basis, along 
with any other axis that your application defines or uses. 
RPC Calls 
Widgets tuned for specific browsers 
Internationalization
Deferred Binding cont'd 
Deferred binding has several benefits: 
● Reduces the size of the generated JavaScript code that 
a client will need to download by only including the code 
needed to run a particular browser/locale instance (used 
by the Internationalization module) 
● Saves development time by automatically generating 
code to implement an interface or create a proxy class 
(used by the GWT RPC module) 
● Since the implementations are pre-bound at compile 
time, there is no run-time penalty to look up an 
implementation in a data structure as with dynamic 
binding or using virtual functions.
conditional compilation - replacement 
A type is replaced with another depending on a 
set of configurable rules. 
IType = GWT.create(TypeImpl.class); 
<replace-with class="...TypeImplFirefox"> 
<when-type-is class="...TypeImpl" /> 
<when-property-is 
name="user.agent" value="gecko"/> 
</replace-with>
properties & property providers 
<property-provider name="property_name"> 
Define a JavaScript fragment that will return the value for the named property at 
runtime. 
//mobilewebapp sample 
<define-property name="formfactor" values="desktop,tablet,mobile"/> 
<collapse-property name="formfactor" values="*"/> 
<property-provider name="formfactor"> 
<![CDATA[ 
.... return (size < 6) ? "mobile" : "tablet"; ... 
return "desktop"; 
]]>
Generators 
Generators are classes that are invoked by the 
GWT compiler to generate a Java 
implementation of a class during compilation 
<generate-with class="...XYGenerator"> 
<when-type-assignable class="...XYType" /> 
</generate-with> 
</module> 
XYType=GWT.create(...); (e.g. RPC, UiBinder)
Generator Class 
Defining a subclass of the Generator class is 
like defining a plug-in to the GWT compiler. 
public class XYGenerator extends Generator { 
public String generate(TreeLogger logger, 
GeneratorContext ctx, 
String requestedClass) 
throws UnableToCompleteException { 
... 
} 
}
emulated JRE 
GWT includes a library that emulates a subset 
of the Java runtime library. 
http://www.gwtproject. 
org/doc/latest/RefJreEmulation.html 
InputStream 
Threads ?
<super-source> 
The <super-source> tag instructs the compiler 
to "re-root" a source path. This is useful for 
cases where you want to re-use an existing 
Java API for a GWT project, but the original 
source is not available or not translatable. 
A common reason for this is to emulate part of 
the JRE not implemented by GWT.
JSNI 
GWT borrows from the Java Native Interface 
(JNI) concept to implement JavaScript Native 
Interface (JSNI). 
Writing JSNI methods is a powerful technique, 
but should be used sparingly because writing 
bulletproof JavaScript code is notoriously tricky. 
Needed for JSO (Javascript Overlay Types)
JSNI cont'd 
public static native void alert(String msg) /*-{ 
$wnd.alert(msg); 
}-*/; 
$wnd: the root browser window GWT widgets 
are being rendered to 
$entry(..): method that makes code reentry 
safe. 
http://www.lustforge.com/2012/11/11/gwt-jsni-variables-an-exhaustive-list/ 
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
Widgets 
UiComponents 
http://www.gwtproject.org/doc/latest/RefWidgetGallery.html 
2.0+ LayoutPanels 
http://www.gwtproject.org/doc/latest/DevGuideUiPanels.html#LayoutPanels 
from the Jul 2013 - GWT Meetup 
What are some of pain points or decisions bad in hindsight? 
... 
● Bad out of box UI 
... 
SmartGWT, GXT
UiBinder 
● The UiBinder is a framework designed to separate Functionality and View 
of User Interface. 
● The UiBinder framework allows developers to build gwt applications as 
HTML pages with GWT widgets configured throughout them. 
● The UiBinder framework makes easier collaboration with UI designers who 
are more comfortable with XML, HTML and CSS than Java source code 
● The UIBinder provides a declarative way of defining (parts of the) User 
Interface. 
● The UIBinder seperates the programmic logic from UI. 
● The UIBinder is similar to what JSP is to Servlets.
UiBinder cont'd 
DSL (xml) to lay-out (declaratively) widgets 
no loops, no conditionals, no if statements 
UiBinder allows you to lay out your user 
interface. 
(offers direct support for internationalization)
UiBinder - syntax 
<!-- HelloWidgetWorld.ui.xml --> 
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' 
xmlns:g='urn:import:com.google.gwt.user.client.ui'> 
<g:HTMLPanel> 
Hello, <g:ListBox ui:field='listBox' visibleItemCount='1'/>. 
</g:HTMLPanel> 
</ui:UiBinder> 
xmlns:g='urn:import:..' binds package to namespace 
ui:field gives name to the widget 
Every one of the widget's methods that follow JavaBean-style conventions for 
setting a property can be used: 
visibleItemCount transl. as setVisibleItemCount(...)
UiBinder - syntax 
public class HelloWidgetWorld extends Composite { 
interface MyUiBinder extends UiBinder<Widget, HelloWidgetWorld> {} 
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class); 
@UiField ListBox listBox; 
public HelloWidgetWorld(String... names) { 
// sets listBox 
initWidget(uiBinder.createAndBindUi(this)); 
for (String name : names) { 
listBox.addItem(name); 
} 
} 
}
UiBinder - misc 
uses the default (with no args) constructor 
@UiField(provided=true) [or read the docs] 
can associate handlers 
@UiHandler("button") 
void handleClick(ClickEvent e) { ..... } 
can inject any type (inst'd through GWT.create) 
<ui:with field='res' type='...'/>
UiBinder - ui:style 
With the <ui:style> element, you can define the 
CSS for your UI right where you need it. 
<ui:style> 
.example { background-color: red } 
</ui:style> 
... 
<g:HTML addStyleNames="{style.red}"/> 
...
UiBinder - ui:style 
<ui:style src="MyUi.css" /> 
<ui:style field='oStyle' src="MyUiOStyle.css"> 
<ui:style type='com.my.app.MyFoo.MyStyle'> 
@UiField 
MyStyle style; 
(CssResource oStyle)
CssResource 
interface MyStyle extends CssResource { 
String enabled(); 
String disabled(); 
} 
@UiField 
MyStyle style; 
style.enabled() (class name) 
http://www.gwtproject.org/javadoc/latest/com/google/gwt/resources/client/CssResource.html
ClientBundle 
public interface Resources extends ClientBundle { 
@Source("Style.css") 
Style style(); 
@Source("Logo.jpg") 
ImageResource logo(); 
public interface Style extends CssResource { 
String mainBlock(); 
String nameSpan(); 
Sprite userPictureSprite(); 
} 
}
GWT-RPC 
BY EXAMPLE
Thanks 
Alberto Mancini 
alberto@jooink.com 
Francesca Tosi 
francesca@jooink.com

More Related Content

PDF
GWT- Google Web Toolkit
PDF
Gwt Presentation
PDF
Building Rich Internet Applications Using Google Web Toolkit
PPT
Google Web Toolkit
PPTX
Gwt ppt
PDF
GQuery a jQuery clone for Gwt, RivieraDev 2011
PDF
Intro to Web Components, Polymer & Vaadin Elements
PPTX
Web Components the best marriage for a PWA
GWT- Google Web Toolkit
Gwt Presentation
Building Rich Internet Applications Using Google Web Toolkit
Google Web Toolkit
Gwt ppt
GQuery a jQuery clone for Gwt, RivieraDev 2011
Intro to Web Components, Polymer & Vaadin Elements
Web Components the best marriage for a PWA

What's hot (20)

PDF
Mobile Browser Internal (Blink Rendering Engine)
PDF
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
 
PDF
Counterclockwise past present future
PDF
Headless Android at AnDevCon3
PPTX
Qt for beginners part 5 ask the experts
 
PDF
Network-Connected Development with ZeroMQ
 
PDF
Qt for beginners part 4 doing more
 
PDF
DIY: Computer Vision with GWT.
PPTX
YaJUG: What's new in GWT2
PDF
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
PDF
2013 04-02-server-side-backbone
PDF
The curious Life of JavaScript - Talk at SI-SE 2015
PDF
WebKit and Blink: open development powering the HTML5 revolution
PDF
Testing cloud and kubernetes applications - ElasTest
ODP
GWT 2 Is Smarter Than You
PDF
Leveraging Android's Linux Heritage at AnDevCon3
PDF
Migrating from Photon to Qt
PDF
An Introduction to the Yocto Embedded Framework 2018
 
PDF
Qt for Python
 
PDF
Plugin-based IVI Architectures with Qt
 
Mobile Browser Internal (Blink Rendering Engine)
[Webinar] QtSerialBus: Using Modbus and CAN bus with Qt
 
Counterclockwise past present future
Headless Android at AnDevCon3
Qt for beginners part 5 ask the experts
 
Network-Connected Development with ZeroMQ
 
Qt for beginners part 4 doing more
 
DIY: Computer Vision with GWT.
YaJUG: What's new in GWT2
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
2013 04-02-server-side-backbone
The curious Life of JavaScript - Talk at SI-SE 2015
WebKit and Blink: open development powering the HTML5 revolution
Testing cloud and kubernetes applications - ElasTest
GWT 2 Is Smarter Than You
Leveraging Android's Linux Heritage at AnDevCon3
Migrating from Photon to Qt
An Introduction to the Yocto Embedded Framework 2018
 
Qt for Python
 
Plugin-based IVI Architectures with Qt
 
Ad

Similar to Javascript as a target language - GWT KickOff - Part 2/2 (20)

PDF
GWT - AppDays - (25 aprile 2014, pordenone)
PDF
Gwt kickoff - Alberto Mancini & Francesca Tosi
PPT
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
PPT
Gwt Presentation1
PDF
GWT - Building Rich Internet Applications Using OO Tools
PPT
Google Web Toolkit Introduction - eXo Platform SEA
PDF
T 0230 Google Wave Powered By Gwt
PPTX
Gwt session
PPTX
Gwt session
PPT
GWT Introduction for Eclipse Day
PDF
The Java alternative to Javascript
PDF
Web polyglot programming
PPTX
GWT Basics
PDF
Rapid and Reliable Developing with HTML5 & GWT
PDF
Google Web Toolkit
PPT
Introduction to Google Web Toolkit
PDF
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
PPT
GWT Training - Session 1/3
PPTX
Ext GWT - Overview and Implementation Case Study
PPT
GWT + Gears : The browser is the platform
GWT - AppDays - (25 aprile 2014, pordenone)
Gwt kickoff - Alberto Mancini & Francesca Tosi
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
Gwt Presentation1
GWT - Building Rich Internet Applications Using OO Tools
Google Web Toolkit Introduction - eXo Platform SEA
T 0230 Google Wave Powered By Gwt
Gwt session
Gwt session
GWT Introduction for Eclipse Day
The Java alternative to Javascript
Web polyglot programming
GWT Basics
Rapid and Reliable Developing with HTML5 & GWT
Google Web Toolkit
Introduction to Google Web Toolkit
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
GWT Training - Session 1/3
Ext GWT - Overview and Implementation Case Study
GWT + Gears : The browser is the platform
Ad

More from JooinK (9)

PDF
(Js) Export your own WebGL Viewer
PDF
Power-up your mobile & web App with WebRTC
PDF
Go native benchmark test su dispositivi x86: java, ndk, ipp e tbb
PDF
Javascript as a target language - GWT kickoff - part1/2
PDF
WebRTC ... GWT & in-browser computation
PDF
Augmented experience: Augmented Reality
PDF
JooinK - DevFest Piemonte 2013
PDF
Web&mobile - 4 ottobre 2012
PDF
JooinK Presentation
(Js) Export your own WebGL Viewer
Power-up your mobile & web App with WebRTC
Go native benchmark test su dispositivi x86: java, ndk, ipp e tbb
Javascript as a target language - GWT kickoff - part1/2
WebRTC ... GWT & in-browser computation
Augmented experience: Augmented Reality
JooinK - DevFest Piemonte 2013
Web&mobile - 4 ottobre 2012
JooinK Presentation

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation_ Review paper, used for researhc scholars
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding

Javascript as a target language - GWT KickOff - Part 2/2

  • 1. Js as a target language: GWT KickOff (Part 2/2) Alberto Mancini - alberto@jooink.com Francesca Tosi - francesca@jooink.com
  • 2. Alberto Mancini alberto@jooink.com http://github.com/jooink http://www.jooink.com http://jooink.blogspot.com
  • 3. Francesca Tosi francesca@jooink.com +FrancescaTosi @francescatosi http://github.com/jooink http://www.jooink.com http://jooink.blogspot.com
  • 4. GWT GWT is a toolkit to develop Ajax web application with Java. The programmer writes Java code and this code is translated into HTML and Javascript via the GWT compiler. The compiler creates browser specific HTML and JavaScript to support all the major browsers correctly.
  • 5. setup 1. java sdk: http://www.java.com/it/download/ (e.g 1.7) 2. eclipse: http://www.eclipse.org/downloads/ (e.g. EE) 3. GWT Eclipse Plugin: https://developers.google.com/eclipse/docs/getting_started 4. Create simple project 5. run ‘dev mode’ 6. open in browser http://127.0.0.1:8888/?get. condeserv=127.0.0.1:9997 (install browser plugin)
  • 6. GWT cont'd - Tools in the Toolkit + GWTc, compiler Java to Javascript + Emulated JRE + Web UI class library (Widgets) + Eclipse Plugin, SpeedTracer, Designer It's open source, completely free, and used by thousands of developers around the world (in Google AdWords,Orkut,Blogger,Groups)
  • 7. Toolkit != Framework Frameworks that may help https://github.com/ArcBees/GWTP model-view-presenter framework http://www.jboss.org/errai CDI, and JPA for GWT http://www.tessell.org/ app framework (on gwt-pectin)
  • 8. GWT cont'd - Developing & Running GWT provides two (3 actually) modes ● Development Mode: allows to debug the Java code of your application directly via the standard Java debugger. ● Web mode: the application is translated into HTML and Javascript code and can be deployed to a webserver. ● SuperDevMode
  • 9. GWT cont'd - Why ? Typed Language Well Known Programming Framework Optimize Browser Independence (quite, almost) + 'Native' through jsni Move Objects between client and server
  • 10. GWT cont'd - History ● GWT 1.0 (2006) ● GWT 1.3 (2007) First Open Source Release, OSX support ● GWT 1.4 (2007) JUnit and ImageBundle ● GWT 1.5 (2008) Java 1.5 support, Overlay Types, DOM API, CSS Themes, Linkers ● GWT 1.6 (2009) EventHandlers, EMMA Support, WAR support, Parallelized Builds ● GWT 1.7 (2009) Newer browser support, IE8, GPE and AppEngine ● GWT 2.0 (2009) DevMode, DraftCompile, UIBinder, LayoutPanel, CodeSplitter, ClientBundle, CssResource ● GWT 2.1 (2010) RequestFactory, Editor Framework, Validation, MVP, Cell Widgets ● GWT 2.2 (2011) GWT Designer, HTML5 support ● GWT 2.3 (2011) Better AppEngine integration ● GWT 2.4 (2011) Maven and RequestFactory enhancements ● GWT 2.5 (2012) SuperDevMode, Elemental, UiRenderers, FragmentMerging, ClosureCompiler
  • 11. GWT cont'd - History ● GWT 2.5.1 (2013) - bugfixes and optimizations ● GWT 2.6.0 (2014) - java 7 - IE10 - Internet Explorer cleanup: IE6/7 ● GWT 2.6.1 (2014) - working on Super Dev Mode Annual Vaadin “The Future of GWT Report” https://vaadin.com/gwt/report-2013 What’s going on. SuperDevMode Java8 JsInterop GSS
  • 12. GWT cont'd - Open Source Project The GWT Steering committee was founded in 2012 to help the GWT project become an even bigger success as an open source project. ● Ray Cromwell, Google ● Artur Signell, Vaadin ● Colin Alworth, Sencha ● Mike Brock, RedHat ● Thomas Broyer ● Stephen Haberman, Bizo ● Daniel Kurka, Google ● Christian Goudreau, Arcbees ● Konstantin Solomatov, Jetbrains
  • 13. Anatomy Module html file Module xml file translatable directories
  • 14. Modules Individual units of GWT configuration are called modules. A module bundles together all the configuration settings that a GWT project needs: ● inherited modules ● an entry point application class name; these are optional, although any module referred to in HTML must have at least one entry-point class specified ● source path entries ● public path entries ● deferred binding rules, including property providers and class generators
  • 15. Deferred Binding Deferred Binding is a feature of the GWT compiler that works by generating many versions of code at compile time, only one of which needs to be loaded by a particular client during bootstrapping at runtime. Each version is generated on a per browser basis, along with any other axis that your application defines or uses. RPC Calls Widgets tuned for specific browsers Internationalization
  • 16. Deferred Binding cont'd Deferred binding has several benefits: ● Reduces the size of the generated JavaScript code that a client will need to download by only including the code needed to run a particular browser/locale instance (used by the Internationalization module) ● Saves development time by automatically generating code to implement an interface or create a proxy class (used by the GWT RPC module) ● Since the implementations are pre-bound at compile time, there is no run-time penalty to look up an implementation in a data structure as with dynamic binding or using virtual functions.
  • 17. conditional compilation - replacement A type is replaced with another depending on a set of configurable rules. IType = GWT.create(TypeImpl.class); <replace-with class="...TypeImplFirefox"> <when-type-is class="...TypeImpl" /> <when-property-is name="user.agent" value="gecko"/> </replace-with>
  • 18. properties & property providers <property-provider name="property_name"> Define a JavaScript fragment that will return the value for the named property at runtime. //mobilewebapp sample <define-property name="formfactor" values="desktop,tablet,mobile"/> <collapse-property name="formfactor" values="*"/> <property-provider name="formfactor"> <![CDATA[ .... return (size < 6) ? "mobile" : "tablet"; ... return "desktop"; ]]>
  • 19. Generators Generators are classes that are invoked by the GWT compiler to generate a Java implementation of a class during compilation <generate-with class="...XYGenerator"> <when-type-assignable class="...XYType" /> </generate-with> </module> XYType=GWT.create(...); (e.g. RPC, UiBinder)
  • 20. Generator Class Defining a subclass of the Generator class is like defining a plug-in to the GWT compiler. public class XYGenerator extends Generator { public String generate(TreeLogger logger, GeneratorContext ctx, String requestedClass) throws UnableToCompleteException { ... } }
  • 21. emulated JRE GWT includes a library that emulates a subset of the Java runtime library. http://www.gwtproject. org/doc/latest/RefJreEmulation.html InputStream Threads ?
  • 22. <super-source> The <super-source> tag instructs the compiler to "re-root" a source path. This is useful for cases where you want to re-use an existing Java API for a GWT project, but the original source is not available or not translatable. A common reason for this is to emulate part of the JRE not implemented by GWT.
  • 23. JSNI GWT borrows from the Java Native Interface (JNI) concept to implement JavaScript Native Interface (JSNI). Writing JSNI methods is a powerful technique, but should be used sparingly because writing bulletproof JavaScript code is notoriously tricky. Needed for JSO (Javascript Overlay Types)
  • 24. JSNI cont'd public static native void alert(String msg) /*-{ $wnd.alert(msg); }-*/; $wnd: the root browser window GWT widgets are being rendered to $entry(..): method that makes code reentry safe. http://www.lustforge.com/2012/11/11/gwt-jsni-variables-an-exhaustive-list/ http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
  • 25. Widgets UiComponents http://www.gwtproject.org/doc/latest/RefWidgetGallery.html 2.0+ LayoutPanels http://www.gwtproject.org/doc/latest/DevGuideUiPanels.html#LayoutPanels from the Jul 2013 - GWT Meetup What are some of pain points or decisions bad in hindsight? ... ● Bad out of box UI ... SmartGWT, GXT
  • 26. UiBinder ● The UiBinder is a framework designed to separate Functionality and View of User Interface. ● The UiBinder framework allows developers to build gwt applications as HTML pages with GWT widgets configured throughout them. ● The UiBinder framework makes easier collaboration with UI designers who are more comfortable with XML, HTML and CSS than Java source code ● The UIBinder provides a declarative way of defining (parts of the) User Interface. ● The UIBinder seperates the programmic logic from UI. ● The UIBinder is similar to what JSP is to Servlets.
  • 27. UiBinder cont'd DSL (xml) to lay-out (declaratively) widgets no loops, no conditionals, no if statements UiBinder allows you to lay out your user interface. (offers direct support for internationalization)
  • 28. UiBinder - syntax <!-- HelloWidgetWorld.ui.xml --> <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui'> <g:HTMLPanel> Hello, <g:ListBox ui:field='listBox' visibleItemCount='1'/>. </g:HTMLPanel> </ui:UiBinder> xmlns:g='urn:import:..' binds package to namespace ui:field gives name to the widget Every one of the widget's methods that follow JavaBean-style conventions for setting a property can be used: visibleItemCount transl. as setVisibleItemCount(...)
  • 29. UiBinder - syntax public class HelloWidgetWorld extends Composite { interface MyUiBinder extends UiBinder<Widget, HelloWidgetWorld> {} private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class); @UiField ListBox listBox; public HelloWidgetWorld(String... names) { // sets listBox initWidget(uiBinder.createAndBindUi(this)); for (String name : names) { listBox.addItem(name); } } }
  • 30. UiBinder - misc uses the default (with no args) constructor @UiField(provided=true) [or read the docs] can associate handlers @UiHandler("button") void handleClick(ClickEvent e) { ..... } can inject any type (inst'd through GWT.create) <ui:with field='res' type='...'/>
  • 31. UiBinder - ui:style With the <ui:style> element, you can define the CSS for your UI right where you need it. <ui:style> .example { background-color: red } </ui:style> ... <g:HTML addStyleNames="{style.red}"/> ...
  • 32. UiBinder - ui:style <ui:style src="MyUi.css" /> <ui:style field='oStyle' src="MyUiOStyle.css"> <ui:style type='com.my.app.MyFoo.MyStyle'> @UiField MyStyle style; (CssResource oStyle)
  • 33. CssResource interface MyStyle extends CssResource { String enabled(); String disabled(); } @UiField MyStyle style; style.enabled() (class name) http://www.gwtproject.org/javadoc/latest/com/google/gwt/resources/client/CssResource.html
  • 34. ClientBundle public interface Resources extends ClientBundle { @Source("Style.css") Style style(); @Source("Logo.jpg") ImageResource logo(); public interface Style extends CssResource { String mainBlock(); String nameSpan(); Sprite userPictureSprite(); } }
  • 36. Thanks Alberto Mancini alberto@jooink.com Francesca Tosi francesca@jooink.com