1 / 20

Intro to GWT

Intro to GWT. By Henry Chan hchan@apache.org. 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.

natala
Download Presentation

Intro to GWT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to GWT By Henry Chan hchan@apache.org

  2. 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?

  3. 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

  4. 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)

  5. 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”

  6. 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)

  7. 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

  8. 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…

  9. 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)

  10. 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

  11. Handling Exceptions • Simple … Server throws an Exception • Client catches it and acts accordingly

  12. GWT Frameworks • GWT-Ext / Gxt • SmartGWT • Vaadin

  13. GWT-Ext / Gxt • GWT-Ext is LGPL written by SanjivJivan • 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

  14. Smart GWT • The successor to GWT-Ext. • Also written by SanjivJivan • 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

  15. 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…

  16. 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?

  17. 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)

  18. Comparisions • Biased … but at least a benchmark • http://vaadin.com/comparison • GWT vs JSF – well, its programming XML + Javascriptvs 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) vsRootPanel.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

  19. Questions and Answers Answer • The answer is 42

  20. 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)

More Related