GWT integration with Vaadin
-
Upload
peter-lehto -
Category
Internet
-
view
60 -
download
3
Transcript of GWT integration with Vaadin
> [] + [];>
> [] + {};> [object Object]
> {} + [];> 0
> {} + {};> var foo = [0];> foo == !foo;> true
> [] + [];>
> [] + {};> [object Object]
> {} + [];> 0
> {} + {};> NaN
> var foo = [0];> foo == !foo;> true
> [] + [];>
> [] + {};> [object Object]
> {} + [];> 0
> {} + {};> NaN
> NaN == NaN;
> var foo = [0];> foo == !foo;> true
> [] + [];>
> [] + {};> [object Object]
> {} + [];> 0
> {} + {};> NaN
> NaN == NaN;> false
> var foo = [0];> foo == !foo;> true
> [] + [];>
> [] + {};> [object Object]
> {} + [];> 0
> {} + {};> NaN
> NaN == NaN;> false
> typeof NaN;
> var foo = [0];> foo == !foo;> true
> [] + [];>
> [] + {};> [object Object]
> {} + [];> 0
> {} + {};> NaN
> NaN == NaN;> false
> typeof NaN;> number
> var foo = [0];> foo == !foo;> true
> [] + [];>
> [] + {};> [object Object]
> {} + [];> 0
> {} + {};> NaN
> NaN == NaN;> false
> typeof NaN;> number
> var foo = [0];> foo == !foo;> true
RequestBuilder RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);try { builder.sendRequest(requestDataString, new RequestCallback() { @Override
public void onResponseReceived(Request request, Response response) { int statusCode = response.getStatusCode(); String text = response.getText();
} @Override
public void onError(Request request, Throwable exception) { // TODO Handle asynchronous problems
} }); } catch (RequestException e) { // TODO Handle synchronous problems}
GWT Remote procedure calls public interface ContactService extends RemoteService { void saveContact(Contact contact); List<Contact> getContacts();}
public interface ContactServiceAsync { void saveContact(Contact contact, AsyncCallback<Void> callback); void getContacts(AsyncCallback<List<Contact>>}
GWT-RPC
Good
• Simple butpowerful concept
• Default solution • Optimized
Bad
• Sending largeobject graph
• Polymorphismproblems
State synchronization public class ContactState extends SharedState { public String name; @DelegateToWidget public int yearOfBirth;}
State synchronization public class ContactState extends SharedState { public String name; @DelegateToWidget public int yearOfBirth;}
@OnStateChange("name")protected void updateName() { doSomethingWithTheName(getState().name);}
Vaadin RPC public interface ContactRpc extends ServerRpc { public void deleteContact(int id);} // Register RPC handler on the serverregisterRpc(new ContactRpc() { @Override public void deleteContact(int id) { ContactDAO.deleteById(id); } });
Vaadin RPC public interface ContactRpc extends ServerRpc { public void deleteContact(int id);} // Register RPC handler on the serverregisterRpc(new ContactRpc() { @Override public void deleteContact(int id) { ContactDAO.deleteById(id); } }); // Send RPC from the clientpublic void sendDelete(int contactId) { getRpcProxy(ContactRpc.class).deleteContact(contactId);}
@Connect(value = Button.class)public class ButtonConnector extends AbstractComponentConnector implements ClickHandler {
@Connect(value = Button.class)public class ButtonConnector extends AbstractComponentConnector implements ClickHandler {
@OnStateChange({ "caption", "captionAsHtml" })void setCaption() { getWidget().setCaptionText(getState().caption);}
@Connect(value = Button.class)public class ButtonConnector extends AbstractComponentConnector implements ClickHandler {
@OnStateChange({ "caption", "captionAsHtml" })void setCaption() { getWidget().setCaptionText(getState().caption);}
void onClick(ClickEvent event) { getRpcProxy(ButtonServerRpc.class).click();}
Vaadin Connectors
Good
• Stateful server • Websocket
support • JSON
Bad
• Stateful server • Tied to
framework
<x-component></x-component>
var proto = Object.create(HTMLElement.prototype); proto.createdCallback = function() { var div = document.createElement('div'); div.textContent = 'This is Custom Element'; this.appendChild(div); }; var XComponent = document.registerElement('x-component', { prototype: proto });
var host = document.querySelector('#host'); var root = host.createShadowRoot(); // Create a Shadow Root var div = document.createElement('div'); div.textContent = 'This is Shadow DOM'; root.appendChild(div); // Append elements to the Shadow Root
index.html<link rel="import" href="component.html" >
component.html<link rel="stylesheet" href="css/style.css"> <script src="js/script.js"></script>
<template id="template"> <style> ... </style> <div> <h1>Web Components</h1> <img src="http://webcomponents.org/img/logo.svg"> </div> </template>
<script> var template = document.querySelector('#template'); var clone = document.importNode(template.content, true); var host = document.querySelector('#host'); host.appendChild(clone); </script> <div id="host"></div>
webcomponents.js
Polyfill
http://webcomponents.org/polyfills/
Web Components Custom Elements HTML Imports Shadow DOM
DOM WeakMap Mutation Observers{
Vaadin Grid Client Widget
Exposed JavaScript API via
JsInterop from GWT 2.7+
Wrapped as PolymerElement
@JsNamespace(JS.VAADIN_JS_NAMESPACE) @JsExport @JsType public class GridComponent… … private final com.vaadin.client.widgets.Grid grid; // Grid widget
public JSColumn addColumn(JSColumn jsColumn, Object beforeColumnId) { grid.addColumn } …
GridComponent
<link rel='import' href='../bower_components/polymer/polymer.html' /> <script type="text/javascript" language="javascript" src=“VaadinGridImport.nocache.js" />
<dom-module id="v-grid"> <template>
… </template> </dom-module>
<script> VGrid = Polymer({ is: “v-grid", properties: { … }, created: function() {
this._grid = new vaadin.GridComponent(); }, attached: function() {
this._grid.attached(this, Polymer.dom(this).querySelector(“table”), Polymer.dom(this.root)); …
},
vaadin-grid.html
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script> <script src="../VaadinGrid/VaadinGrid.nocache.js"></script>
<body> <v-grid rows=1> …
index.html
Lessons learned today1. Vaadin is server driven high abstraction level UI framework
2. GWT is used for client side rendering
Lessons learned today1. Vaadin is server driven high abstraction level UI framework
2. GWT is used for client side rendering
3. Vaadin connectors form a bridge between GWT and Vaadin
Lessons learned today1. Vaadin is server driven high abstraction level UI framework
2. GWT is used for client side rendering
3. Vaadin connectors form a bridge between GWT and Vaadin
4. Web Components will be the next big thing in the web!
Lessons learned today1. Vaadin is server driven high abstraction level UI framework
2. GWT is used for client side rendering
3. Vaadin connectors form a bridge between GWT and Vaadin
4. Web Components will be the next big thing in the web!
5. Polymer polyfills today’s browsers to support emerging features
Lessons learned today1. Vaadin is server driven high abstraction level UI framework
2. GWT is used for client side rendering
3. Vaadin connectors form a bridge between GWT and Vaadin
4. Web Components will be the next big thing in the web!
5. Polymer polyfills today’s browsers to support emerging features
6. Vaadin Components will utilize Polymer providing frameworkindependent way of using the best component library available
@peter_lehto expert & trainer
slides slideshare.net/peterlehto
Je zult maar letter wezen. Goed, ik ben niet ontevredet. Maar het valt niet mee in deze zeventiger jaren tot het vaderlandse alfabet te behoren. Foto-zetterijen wringen je steeds in steeds ingevikkelder. Je zult maar letter wezen. Goed, ik ben