Download GWT - Meetup

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Scala (programming language) wikipedia , lookup

Object-oriented programming wikipedia , lookup

C Sharp syntax wikipedia , lookup

Java (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Java performance wikipedia , lookup

JavaScript wikipedia , lookup

Transcript
Intro to GWT
By Henry Chan
[email protected]
Brain Teaser to start the evening…
There are 100 houses numbered 1 to 100. During
Halloween, House#1 gives 1 candy, House#2 gives 2
candies, etc up to House#100 which gives
100candies.
Jack goes trick-or-treating to these houses and gets
candy from each house except for one (House#X)
because they gave him a “Trick” instead.
Question: How do you calculate X in O(1) complexity?
What is GWT?
• Is it a JEE framework or is it a just a toolkit?!?
• The heart of GWT is its Java -> Javascript
compiler
• GWT –RPC - Java->Javascript->Java … if you
ever used DWR … this is way kewler
• UI Library (your vanilla HTML Widgets, Layout
Managers – feels like Spring)
• Plugin/Development environment
Current Release
• Current stable release is 1.7.1
• However 2.0 milestone2 is out
• Best feature of 2.0 is OOPHM (Out of Process
Hosted Mode)
Hello World
• A TextBox and a Send button (UI objects – aka
widgets, components)
• Sends a message (GWT-RPC) to the server
• Sent with a onClick Event - handlers
• Written with an Eclipse
• Entry Point: public void onModuleLoad() {
• Config file … .gwt.xml
• Default output directory … “war”
No Javascript?
• A moment of truth … there’s theory and then
there’s practice … Javascript can’t die
• Events are handled on the components, but
every so often, you’ll still need Javascript for
something whether it be integration or for
some hackery reason.
• Welcome JSNI (Javascript Native Interface)
Embedding GWT or a whole page as a
GWT Module…
• Basically RootPanel.get(stringID) or
RootPanel.get()
• If you plan on mixing GWT with some HTML
code, use RootPanel.get(stringID) otherwise
your whole page will be a GWT App
• An good example of an embedded GWT
Module could be Google Maps
Compiled code
• 6 permutations – 6 browsers
• Can specify generated code to be obfuscated
or not
• Yeah – compilation can take a long time.
Reduce the permutations via the .gwt.xml file
• Or run in development mode with the GWT
Hosted Browser…
Running in Development Mode
(previously known as hosted mode)
• Simple in concept …
• You don’t need to wait those 15-30s to wait
for your code to compile (from Java to
Javascript). You make a change (reload your
browser in some cases) and can even put
breakpoints
• Can work with Firefox, IE too – OOPHM (GWT
version 2.0)
GWT RPC
• Like DWR, but you work with Java to Java on
both ends. Done via an AJAX POST
• Send a Data Transfer Object (DTO) across
to/from the client to server
• All DTOs must implement IsSerializable
• xxxService.java
• xxxServiceAsync.java
• xxxServiceImpl.java
Handling Exceptions
• Simple … Server throws an Exception
• Client catches it and acts accordingly
GWT Frameworks
• GWT-Ext / Gxt
• SmartGWT
• Vaadin
GWT-Ext / Gxt
• GWT-Ext is LGPL written by Sanjiv Jivan
• Unfortunately GWT-Ext will have no further
major releases
• GWT-Ext (aka GXT) is GPL or Commerical
licences are available
• Basically LGPL is better than GPL if you are
using it to build a webapp for a customer who
doesn’t want their Business Rules to be open
source
Smart GWT
•
•
•
•
The successor to GWT-Ext.
Also written by Sanjiv Jivan
Like GWT-Ext, it is also LGPL
… except for the EE version of it which is of
course commercial <sigh/>
• Commercial version comes with widget->data
binding
DTO (Data Transfer Object)
•
•
•
•
•
Loosely coupled design pattern
How much power do u give the framework?
JSF has managed bean/backing beans
Wicket binds component on the server
GWT ... Is it a framework? Uses RPC to send the DTO.
Biggest difference is that there’s no real binding of UI
transfer objects to RemoteServiceImpl. Populating of
the DTO is done on the front-end in GWT.
• Flexible or just more work and maintenance? Hmmm…
If u like DTOs…
• Check out Dozer
• Its like BeanUtils.copyProperties(destObj, origObj)
except on steroids.
• Note GWT does not support BigDecimal
• Probably other ways to use hibernate with GWT (i.e.
Gilead), but the question is: To DTO or not to DTO?
When does the DTO look identical to the Domain
Objects? Do we need DAOs if we are *only* talking to
a RDMS (no filesystem, LDAP, Web Service, JMS
involved)?
• To DTO or not to DTO?
Vaadin
•
•
•
•
Finnish for “I insist”
Released publically on May 2009
Feels like Swing (from front-end to DB)
The only free GWT framework with widget
databinding (HbnContainer)
Comparisions
•
•
•
•
•
•
•
•
Biased … but at least a benchmark
http://vaadin.com/comparison
GWT vs JSF – well, its programming XML + Javascript vs programming in Java. In
JSF, say when a “I will send a cheque” radio button is checked, you have to disable
all Credit card fields using Javascript (or go to the server and run render)
GWT vs Wicket. Wicket is a nice MVC model. Again Javascript integration with
Wicket is messy. Also (not to bash Wicket), but their components aren’t that
“Rich”. Its just vanilla HTML.
GWT vs Struts2. Did I say compare? Struts2 dojo plugin has been deprecated.
Yikes (that’s pretty major). Struts2 can work in parallel to GWT (RootPanel.get(id)
vs RootPanel.get()). You can even use FreeMarker/Velocity with GWT
Same can be said about SpringMVC
Among all the Java frameworks, the Showcase for GWT frameworks are the most
complete. Forget the friggin code snippets here and there. Their showcases run
right off of your IDE.
You can put break-points here, change some code and can also can view source
from your IDE or from your Browser
Questions and Answers Answer
• The answer is 42
Answer to Brain Teaser
There are 100 houses numbered 1 to 100. During Halloween, House#1
gives 1 candy, House#2 gives 2 candies, etc up to House#100 which
gives 100candies.
Jack goes trick-or-treating to these houses and gets candy from each
house except for one (House#X) because they gave him a “Trick”
instead.
Question: How do you calculate X in O(1) complexity?
Answer:
To find the house that Jack missed out on, take the summation of 1 to
100 and subtract the number of candies Jack collected. i.e. if Jack
collected 5008 candies across those 99 houses, the house number
he missed was 42 (the summation of 1 to 100 is 5050 and
subtracting 5008 would give 42)