79
What’s New in GWT? David Chandler Google Web Toolkit Team Atlanta, GA USA [email protected] 1

What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

What’s New in GWT?David ChandlerGoogle Web Toolkit TeamAtlanta, GA [email protected]

1

Page 2: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

AgendaWhy rich Web apps with GWT?

GWT Quickstart

Developer tools

GWT performance for your users

Building with GWT 2.12

2

Page 3: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT in 10 sec

AsynchronousJavaScriptAndXML++

3

Page 4: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT in 60 secOpen source Java to JavaScript compiler

Lets you write rich Web apps in Java

Cross-browser just works (FireFox, Chrome, Safari, IE 6+)

Produces small, fast JavaScript

Easy (and efficient) RPC

Great for large projects / teams

4

Page 5: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

5

Browser-Proof Your JS Code

IE

Firefox

Safari

Chrome

Opera

5

Page 6: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

6

No plugins required

VML Flash

Silverlight

6

Page 7: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

7

Can you find the bug?

Hint: JavaScript is a dynamic language

7

Page 8: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

8

Java is a static language

Catch errors at compile time

8

Page 9: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

9

Completion, refactoring...

9

Page 10: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

10

Eating our own dogfood

+= AdSense, Maps, Docs, Groups...

10

Page 11: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

DemosBooked In

Typing race

11

Page 12: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Rich ecosystemwww.gwtmarketplace.com

12

Page 13: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

More ecosystemUtil: GIN, gwt-dnd, gwt-fx, gwt-comet, ...Widgets: EXT-GWT, Smart-GWT, ...Frameworks: Vaadin!

13

Page 14: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

14

May 2006 GWT 1.0 Launch at JavaOne

… …

Aug 2008 GWT 1.5 Java 5 language support

Apr 2009 GWT 1.7 Dedicated IE8 support

Fall 2009 GWT 2.0 UIBinder (XML template), runAsync()

Oct 2010 GWT 2.1 MVP, RequestFactory, Spring Roo

4+ years in review

14

Page 15: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Productivity for developers

- Language, IDEs, tools, libraries

- People, ecosystem

Performance for users

- 'Perfect' caching

- Whole program optimization

15

GWT delivers...

15

Page 16: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Developing with GWTDevelop

- Google Plugin for Eclipse, GWT Designer, STS / Roo

Debug

- In Eclipse with dev mode browser plugin

Optimize

- SpeedTracer for GWT, App Engine, Spring Insight

Deploy

- Standard WAR or one-button push to App Engine

16

Page 17: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Google Plugin for Eclipse

17

Page 18: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Google Plugin for EclipseEasiest way to get latest GWT, GAE SDKs

Debug / Run / Optimize / Deploy

Wizards (new module, entry point, ClientBundle, UiBinder)

Quick fixes (auto-create RPC Async interface)

Run As | GWT JUnit Test

Maven integration via m2eclipse plugin

18

Page 19: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT Designer Java, ui.xml

19

Page 20: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT Designer & UiBinder

20

Page 21: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT Designer CSS Editor

21

Page 22: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

22

Development cycle

HitRefresh

QuickTest

WriteCode

22

Page 23: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

DemoDev mode

Set breakpoint

23

Page 24: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

24

How dev mode works

Java Virtual Machine

Duke, the Java mascotCopyright © Sun Microsystems Inc., all rights reserved.

Web Server

A real browser

Code Server

24

Page 25: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

25

Debug in dev mode

25

Page 26: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

26

Compile for Production

Your app running here.No plugins.

Source files:

Code, CSS, Images, Resources, … GWT

Compiler

26

Page 27: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Optimize with Speed Tracer

27

Page 28: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Launch SpeedTracerFrom Chrome...

Or from Eclipse...

28

Page 29: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Server traces GAE, tcServer

29

Page 30: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

One click deploy to GAE

30

Page 31: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

31

• Perfect Caching

• ClientBundle

• data: URLs & MHTML packaging

• Developer guided code splitting

• Compiler optimizations

Latency

Number of connections

Bandwidth

Browser Performance

Performance for your users

31

Page 32: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

32

Perfect caching

A83B1C.cache.html… … ………   ………… … … ……… …………… … …………………  … … ……     …  …… … …… … … ……… ………… ………… ……… … …… …… … … …… … F7312.cache.txt …… 6C5BA.cache.png  …… ……  …… …  ………… … ……… …   ……… ……… ……… … ……… … …… … …………… ………………… ……… … …………   ………………… …… … … … …… … ……

foo.nocache.js……… … ………… ………  … …… A83B1C.cache.html … …

6C5BA.cache.png F7312.cache.txt

index.html… ………… ………… ………… … … ………  ……………… … … … … …… …… <script src='foo.nocache.js' … > …………

}}

FOREVERCacheable

HTTPIf-Modifed-Since

32

Page 33: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

33

Image sprites for free

∑ Separate Bundled

20,558 bytes

6,824 bytes

11 separate images

1 bundled image

33

Page 34: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

34

Without ClientBundle

34

Page 35: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

35

Deferred binding

14800 ms4836 ms1997 ms7148 msDOM manipulation

2469 ms1520 ms918 ms2477 msinnerText=...

-1386 ms908 ms-textContent=...

4078 ms2053 ms1276 ms2876 msTypical portable setInnerText()

IEOperaWebkit (Safari)Firefox

Improvement 39%32%29%14%

35

Page 36: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

“The fastest code is that which does not run.”

Joel Webber

GWT co-creator

GWT compiler optimization

36

Page 37: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT compiler optimizationDoes all the stuff you’d do by hand in a tight JS app

- Shrinking (obfuscation)

- Modularization (pay only for what you use)

- Dead code removal

- Method inlining

…but automated and even tighter

Developer-guided code splitting (runAsync)

37

Page 38: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

What’s new in 2.2?Integration with Spring / Roo

SafeHTML wrappers

GPE: Maven support, integration GWT Designer

Application framework

- RequestFactory, JSR 303 validation

- Activities and Places

Cell Widgets and Editor framework

GWT Canvas + Audio / Video38

Page 39: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Four flavors of RPC1. RequestBuilder + JSONParser (see RESTY-GWT)

2. RequestBuilder + XMLParser

3. GWT-RPC (easiest)

4. RequestFactory (new in 2.1)

39

Page 40: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT-RPC@RemoteServiceRelativePath("greet")public interface GreetingService extends RemoteService { String greetServer(String name) throws IllegalArgumentException;}

public interface GreetingServiceAsync { void greetServer(String input, AsyncCallback<String> callback) throws IllegalArgumentException;}

public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService{ public String greetServer(String input) throws IllegalArgumentException { ...

}}

40

Page 41: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Simple, powerful GWT-RPCSend / receive Plain Old Java Objects (POJO)

- Easy: interface, async, & implementation

- Versioned to help keep client & server in sync

- Even smaller than JSON

- Supports polymorphism

- No JavaScript hijacking risk (JSON attack)

- Easy to find all calls to given service in IDE

41

Page 42: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT 2.1 RequestFactoryNewer alternative to GWT-RPC

Designed for data-oriented services

- Higher level of abstraction than GWT-RPC

- Foundation for future caching / batching

Even faster than GWT-RPC

- JSON-based == very fast (no serialization / deserialization required)

- Tracks changes on the client and sends only diffs

42

Page 43: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

RequestFactoryThe entity / DTO problem

EntityProxy / ValueProxy

Service stub interfaces extend RequestContext

AppRequestFactory extends RequestFactory

GWT.create(MyAppRequestFactory.class)

43

Page 44: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

EntityProxy@Entitypublic class ItemList extends DatastoreObject{ private String name; private Key<AppUser> owner; private ListType listType; @Embedded private List<ListItem> items; // value type

...}

@ProxyFor(ItemList.class)public interface ItemListProxy extends DatastoreObjectProxy{ // TODO enums work! public enum ListType {NOTES, TODO} String getName(); void setName(String name); List<ListItemProxy> getItems();

AppUserProxy getOwner(); // NOT Key...

}

44

Page 45: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

DatastoreObjectpackage com.listwidget.domain;public class DatastoreObject{ @Id private Long id; private Integer version = 0; @PrePersist void onPersist() { this.version++; }

...}

package com.listwidget.shared.proxy;public interface DatastoreObjectProxy extends EntityProxy{ Long getId(); Integer getVersion();}

45

Page 46: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

ValueProxypublic class ListItem // POJO{ private String itemText; private Date dateCreated; public Date getDateCreated() { return dateCreated; }}

@ProxyFor(value = ListItem.class)public interface ListItemProxy extends ValueProxy{ String getItemText(); void setItemText(String itemText); Date getDateCreated();}

46

Page 47: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Making a RequestFactorypublic interface ListwidgetRequestFactory extends RequestFactory{ @Service(value = ItemListDao.class, locator = DaoServiceLocator.class) interface ItemListRequestContext extends RequestContext { Request<List<ItemListProxy>> listAll(); Request<Void> save(ItemListProxy list); Request<ItemListProxy> saveAndReturn(ItemListProxy newList); } ItemListRequestContext itemListRequest();}

private final ListwidgetRequestFactory rf = GWT.create(ListwidgetRequestFactory.class);

47

Page 48: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Using RequestFactory @Override public void persistList(String listName) { final ListwidgetRequestFactory rf = this.clientFactory .getRequestFactory(); ItemListRequestContext reqCtx = rf.itemListRequest(); final ItemListProxy newList = reqCtx.create(ItemListProxy.class); newList.setName(listName); newList.setListType(ListType.TODO); reqCtx.saveAndReturn(newList).fire(new Receiver<ItemListProxy>() { @Override public void onSuccess(final ItemListProxy savedList) { // Refresh table listDataProvider.getData(); } }); }

48

Page 49: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Using RequestFactory @Override public void update(int index, ItemListProxy obj, final String newName) { ItemListRequestContext reqCtx = clientFactory.getRequestFactory() .itemListRequest(); ItemListProxy editable = reqCtx.edit(obj); editable.setName(newName); reqCtx.save(editable).fire(new Receiver<Void>() { @Override public void onSuccess(Void response) { eventBus.fireEvent(new MessageEvent(newName + " updated", MessageType.INFO)); } }); }

49

Page 50: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Using RequestFactory private void getData() {

// To retrieve relations and value types, use .with() Request<List<ItemListProxy>> findAllReq = rf.itemListRequest() .listAll().with("owner");

// Receiver specifies return type findAllReq.fire(new Receiver<List<ItemListProxy>>() { @Override public void onSuccess(List<ItemListProxy> response) { updateRowData(0, response); } }); }

Text

50

Page 51: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Using RequestFactory editList = reqCtx.edit(editList); List<ListItemProxy> items = editList.getItems(); // must initialize collections if (items == null) { editList.setItems(new ArrayList<ListItemProxy>()); } editList.getItems().add(newItem); reqCtx.save(editList).with("items").to(new Receiver<Void>() { @Override public void onSuccess(Void response) { itemsProvider.setList(editList.getItems()); itemsProvider.refresh(); } }).fire();

51

Page 52: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT MVP - ConceptsView

- Interface + implementation

- Interface enables testing without GWTTestCase

- Typically expensive to construct so make reusable

Presenter

- No Widgets, just business logic

- Middle man between service layer and views

52

Page 53: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT MVP - ConceptsActivity

- Similar to presenters, but higher level

- “wake up, set up, show up”

- Automatically warn users before leaving

- Instantiate view (or obtain from factory)

- Mapped from Places

53

Page 54: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT MVP - ConceptsPlace

- Place represents bookmarkable state of an activity

- PlaceController makes back button / bookmarks work like users expect

- PlaceTokenizers map to / from String tokens on URL

54

Page 55: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Activitypublic class EditListActivity extends AbstractActivity implements Presenter{ private ClientFactory clientFactory; private EventBus eventBus;

public EditListActivity(ClientFactory cf, EditListPlace editListPlace) { this.clientFactory = cf; this.itemListToken = editListPlace.getToken(); }

@Override public void start(final AcceptsOneWidget panel, EventBus eventBus) { this.eventBus = eventBus;

...panel.setWidget(clientFactory.getEditListView());

}...

}

55

Page 56: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Placepublic class EditListPlace extends Place{ private String token; public EditListPlace(String token) { this.token = token; } public String getToken() { return token; } public static class Tokenizer implements PlaceTokenizer<EditListPlace> { public EditListPlace getPlace(String token) { return new EditListPlace(token); } public String getToken(EditListPlace place) { return place.getToken(); } }}

56

Page 57: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

ActivityMapperpublic class AppActivityMapper implements ActivityMapper {

private ClientFactory clientFactory;

public AppActivityMapper(ClientFactory clientFactory) { super(); this.clientFactory = clientFactory; }

@Override public Activity getActivity(Place place) { if (place instanceof EditListPlace) { return new EditListActivity(clientFactory, (EditListPlace) place); } if (place instanceof ListsPlace) { return new ListsActivity(clientFactory); } return null; }}

57

Page 58: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

PlaceHistoryMapper/** * PlaceHistoryMapper interface is used to attach all places which the * PlaceHistoryHandler should be aware of. This is done via the @WithTokenizers * annotation or by extending PlaceHistoryMapperWithFactory and creating a * separate TokenizerFactory. */@WithTokenizers({ ListsPlace.Tokenizer.class, EditListPlace.Tokenizer.class })public interface AppPlaceHistoryMapper extends PlaceHistoryMapper{}

58

Page 59: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Places: Moving parts

59

Page 60: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Places: Go to

60

Page 61: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Places: Back and forth

61

Page 62: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Get activated

62

Page 63: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Strategies

63

Page 64: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Strategies

64

Page 65: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Activities and Places wiring// Start ActivityManager for the nav (west) panel with our WestActivityMapperActivityMapper westActivityMapper = new WestActivityMapper(clientFactory);ActivityManager westActivityManager =

new ActivityManager(westActivityMapper, eventBus);westActivityManager.setDisplay(westPanel);

// Start ActivityManager for the main (center) panel with our CenterActivityMapperActivityMapper centerActivityMapper = new CenterActivityMapper(clientFactory);ActivityManager centerActivityManager =

new ActivityManager(centerActivityMapper, eventBus);centerActivityManager.setDisplay(centerPanel);

// Start PlaceHistoryHandler with our PlaceHistoryMapperPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);historyHandler.register(placeController, eventBus, defaultPlace);

RootPanel.get().add(dockLayoutPanel);// Goes to place represented on URL or default placehistoryHandler.handleCurrentHistory();

65

Page 66: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Cell WidgetsFast, lightweight table rendering

Data binding withDataProviders, ValueUpdaters

Scrolling and paging controls

Sortable columns, adjustable width

TextBox, IntegerBox, ValueBox<T>

66

Page 67: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Cell Widgets

67

Page 68: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Editable Column// Editable column for list namenameColumn = new Column<ItemListProxy,String>(new EditTextCell()){ @Override public String getValue(ItemListProxy list) { return list.getName(); }};

68

Page 69: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Custom Column type

// Note Flyweight pattern: only one instance of HyperlinkCell passed to the ColumnColumn<ItemListProxy, Hyperlink> linkColumn =

new Column<ItemListProxy, Hyperlink>(new HyperlinkCell()){ @Override public Hyperlink getValue(ItemListProxy list) { String proxyToken =

clientFactory.getRequestFactory().getHistoryToken(list.stableId()); String historyToken =

clientFactory.getHistoryMapper().getToken(new EditListPlace(proxyToken));Hyperlink h = new Hyperlink(list.getName(),historyToken);

return h; }};

69

Page 70: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Populating a CellTablepublic static class MyDataProvider extends AsyncDataProvider<ItemListProxy>{ @Override protected void onRangeChanged(HasData<ItemListProxy> display) { // To retrieve relations and value types, use .with() Request<List<ItemListProxy>> findAllReq = rf.itemListRequest() .listAll().with("owner"); // Receiver specifies return type findAllReq.fire(new Receiver<List<ItemListProxy>>() { @Override public void onSuccess(List<ItemListProxy> response) { updateRowData(0, response); } }); }}

this.myDataProvider = new MyDataProvider(requestFactory);

70

Page 71: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

Updating with a CellTablepublic class NameFieldUpdater implements FieldUpdater<ItemListProxy, String>{ @Override public void update(int index, ItemListProxy obj, final String newName) { ItemListRequestContext reqCtx = clientFactory.getRequestFactory() .itemListRequest(); ItemListProxy editable = reqCtx.edit(obj); editable.setName(newName); reqCtx.save(editable).fire(new Receiver<Void>() { @Override public void onSuccess(Void response) { eventBus.fireEvent(new MessageEvent(newName + " updated", MessageType.INFO)); } }); }};

// Make list name field editabledisplay.getNameColumn().setFieldUpdater(new NameFieldUpdater());

71

Page 72: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT now has java.util.Logging emulation

Configure in your .gwt.xml

Easily enable remote logging, too

GWT Logging

72

Page 73: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT secrets-compileReport

73

Page 74: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT secrets: faster compile

- -draftCompile skips optimizations

- Set only one user-agent in gwt.xml for dev

- Careful with RPC polymorphism

74

Page 75: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT secrets: shrink JS

- -XdisableClassMetadata: Disables some java.lang.Class methods (e.g. getName())

- <set-property name="compiler.stackMode" value="strip"/>Removes client-side stack trace info (can reduce code size up to 15%)

- <set-configuration-property name="CssResource.obfuscationPrefix" value="empty"/>

75

Page 76: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT secrets: shrink JS

- enum obfuscation

- -XdisableCastChecking: Disables run-time checking of cast operations(use with caution)

- See GWT FAQ, CompilerParameters.gwt.xml

76

Page 77: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT speak“Very productive environment for Java developers, but there is a learning curve”

“UI layout and styling is a challenge”

“GWT has enabled our team to run much faster than we could otherwise”

“Would be impossible to write our app without GWT”

77

Page 78: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

GWT books

http://code.google.com/webtoolkit/books.html

78

Page 79: What’s New in GWT? - Jfokus · GWT 2.1 RequestFactory Newer alternative to GWT-RPC Designed for data-oriented services-Higher level of abstraction than GWT-RPC-Foundation for future

79

Thank you!Where to get it:http://code.google.com/webtoolkit/

Wiki, issue tracker, source:http://code.google.com/p/google-web-toolkit/

Official GWT blog:http://google-web-toolkit.blogspot.com/

Twitter:@googledevtools

79