Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

101
Joonas Lehtinen, PhD Vaadin Ltd - CEO vaadin.com/vaadin Rich Web Applications in Server-side Java without Plug-ins or JavaScript @joonaslehtinen

description

Get introduced to the Vaadin framework by one of its core developers. Vaadin provides a desktop-like programming model on the server for creating Rich Internet Applications (RIAs) in plain Java - without the need for HTML, XML, plug-ins or JavaScript. In this session, Joonas lays out the key concepts of the server-side RIA development model and compares it to client-side RIA. To demonstrate the use of framework, an example application is developed during the session step-by-step. The presentation is concluded with pointers on how to start developing your own applications with Apache-licensed Vaadin-framework. You'll learn: * How to create a desktop like web application in Java * Difference between page oriented, client-side RIA and server-side RIA architectures * How Vaadin can be extended with Google Web Toolkit

Transcript of Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Page 1: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Joonas Lehtinen, PhDVaadin Ltd - CEO

vaadin.com/vaadin

Rich Web Applications in Server-side Java without

Plug-ins or JavaScript

@joonaslehtinen

Page 2: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 3: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Vaadin is a UI framework

for rich web applications

Page 4: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

htmljava

Page 5: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

History behind Vaadin

Page 6: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

healthcare portal, >100 kloc of perl, .. web 1.0, netscape, ie5, ie6, ...

1998

Page 7: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

healthcare portal, 100 kloc of perl, .. web 1.0, netscape, ie5, ie6, ...

Page 8: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

object oriented design, desktop, Java, U and I ...thinking of

Page 9: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

desktop programming paradigm for web! found

Page 10: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

desktop programming paradigm for web! found millstone ajax google web toolkit re-released as

2000

2002

2005

2008

Page 11: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

millstone ajax goolge web toolkit re-released as

2009

Page 12: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

plug-ins, mainstream

2010

2011

Used by >50.000 developers in >150 countries

Building apps for fortune 500, startups, governments, ... across all industries

Collaborating by conributing > 200plug-ins and helping each other on a forum with >1500 posts / m

Backed by 50+ person full-time team

Page 13: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

see our transparent vaadin.com/roadmap

2012

Page 14: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

ApacheLicense

Page 15: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Discussion

VaadinTechnology, Features, Getting started

Server-side RIAWhat is it? Pros & cons?

In practiceCoding a Vaadin application step-by-step

Contents

Page 16: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Server-side RIA

Page 17: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

“Web 1.0”

DOM

Client Server

ViewHTML Page

over HttpResponse

Controller

Model

Parameters overHttpRequest

DB2

3

4

5

1

Page 18: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

client-side ria

fat client

Page 19: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Client-side RIA

DOM

Client Server

View

Controller

Model

DB2

3

4

5

1

Requested datato view as

XML / JSON

Changes to modelencoded as parameters

Page 20: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

challengeweb is

not easy

Page 21: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

weak typing

Codecompletion?

Refactoring?

Compile-time

checking?

AutomatedAPI docs?

Page 22: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

JavaScriptfacilitated spaghetti

weak typing

> 10k SLOC

> 1 developers+

+

Page 23: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

features

performancebrowsers

aredifferent

bugs

Page 24: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Google Web Toolkit

Page 25: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Java toJavaScriptCompiler

Subset of

java.lang, java.util

Widgetset

Your Application UI

IE6

IE7

Firefox

Safari

Page 26: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

simpler• 100% Java• Static typing• Object oriented• Excellent tooling

Page 27: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

less bugs • Stop debugging

JavaScript spaghetti • Ignore most

browser differences

Page 28: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

client-side• UI in client• Asyncronous RPC• Services (for UI)

Page 29: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Building wonderful apps doesn’t require writing fat web clients.

Page 30: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

server-side ria

thin client

Page 31: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Server-side RIA

DOM

Client Server

ViewHTML Pageover HttpResponse

Controller

Model

Parameters overHttpRequest

DB4

5

6

2

Term

inalAdapter

Term

inalAdapter

Automated bythe RIA framework

3

7

1

9

8

Handled by the framework

Page 32: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Strong programming model

simpler• 100% Java• Strong typing• Object oriented• Excellent tooling

High level

less bugs• No JavaScript debugging• Ignore browsers

Page 33: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

server enviroment• Access any library• Use any language• Runtime is not

limited by browser• Trusted• Well defined

Page 34: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

simplifiedcommunications• No RPC layer• No services (for UI)• Synchronous• Direct access to

server API

Page 35: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

secure• Code stays in server• No services (for UI)• Predictable runtime

Page 36: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

not as scalableUI state is stored in the server memory

Page 37: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Measured 12.000 active concurrent users per server for a ticketing app

* Amazon EC2-large; 20.622 Ajax requests / minute peak; limited by storage layer

Page 38: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

no offline modeconnection to server is always required

Page 39: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

#1 benefitdevelopmentis really fast

Page 40: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 41: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

2 Java class files~ 50 LOC + importsno HTMLno CSSno JavaScriptno Cut-n-Paste

Page 42: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

https://github.com/jojule/DocumentManager

Page 43: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Vaadin Framework

Page 44: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Developerexperience

Userexpecience

Scalability

goals

Page 45: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

123ideas

Page 46: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

1amazingcomponents

Page 47: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

User IntefaceData Source

Theme

Page 49: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 50: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 51: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

User IntefaceData Source

Theme

Page 53: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

User IntefaceData Source

Theme

Page 54: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 55: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

InMemory, Bean, Method, Collection, JDBC, JPA, Hibernate, TextFile, FileSystem, Properties, EclipseLink, Lucene, Mockups, GAE, ... Your’s

Page 56: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

example

SQLContainer

Page 57: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Tableor any other UI component

FreeformQuery

SQLContainer

JDBC

SELECT * FROM ...

Page 58: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

connectionPool = new SimpleJDBCConnectionPool( "org.hsqldb.jdbc.JDBCDriver", "jdbc:hsqldb:mem:sqlcontainer", "password", "", 2, 2); SQLContainer container = new SQLContainer( new FreeformQuery( "SELECT * FROM people", Arrays.asList("ID"), connectionPool)); Table table = new Table(null, container);

Page 59: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Tableor any other UI component

TableQuery

SQLContainer

JDBC

Database Table

Page 60: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

• lazy loading• advanced filtering• sorting• connection pooling• transactions• optimistic locking• autocommit mode

Page 61: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

• HSQLDB• MySQL• PostgreSQL • Oracle• MS SQL Server

Page 62: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

2combine power of• Server-side RIA• Google Web Toolkit

Page 63: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

javascriptjavajson / xmlany language any language

Layers of abstraction

browserbrowserfrontendserver

backendserver

required optional optionalrequired

RPC

optional

Vaa

din

required optionalrequired

GW

T

requiredrequired

Ext

JS

requiredrequired

required requiredX

Page 64: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

How does it work, really?

Page 65: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 66: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

• Initial HTML• CSS (theme)• Images• JavaScript

830k total

250k

compress

120k

reducedwidgetset

Page 67: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

• name=”Joonas”• button clicked

150 bytes

Page 68: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 69: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

• name=”Joonas”• button clicked

150 bytes

• Add notification

466 bytes

Page 70: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Vaadin UI component architecture

Java

• Google Web Toolkit

“UI Component”• Button, Table, Tree, ...• Server-side data• Full Java API

“Widget”• Client-side peer for

the component• Runs on JavaScript

HTTP(S)

Java

• Compiled with JDK

Page 71: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Creating new UI components is really easy

Page 72: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 73: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Implement two classes

Automatic“UI Component”• Define API• Receive client events• Send UI updates

back

Server-side

“Widget”• Render to DOM• Collect user events

Client-side

Page 74: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 75: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 76: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 77: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 78: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 79: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Vaadin += GWT

Page 80: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 81: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

GWTCompatible

Page 82: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Server-

Client-si

deO

ptimized for

Productivity

Opt

imiz

ed fo

r

Cont

rol

Page 83: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Server-

Client-side

Opt

imiz

ed fo

r

Prod

uctiv

ity

Optim

ized for

Control

Page 84: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

CommercialSupport

Page 85: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

3embracejava

Page 86: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Any JVMLanguage

Page 87: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

val layout = new VerticalLayout(width = 100 pct, height = 100 pct) {

add(new Label(content = "Persons"))add(new Table(width = 100 pct, height = 100 pct),

ratio = 1)add(new HorizontalLayout(spacing = true) {

add(new Button("Edit selected", _ => editClicked())) add(new Button("Add new", _ => addNewClicked()))

})}

getMainWindow.setContent(layout)

Scalawith Scaladin add-on

Page 88: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Internet ExplorerChromeFirefoxSafariOpera

iOSAndroid

6..

Page 89: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Nobrowserplugins

Nothing toinstall

Page 90: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Servlet Portlet

(most) clouds

Page 91: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Apache Tomcat, version 4.1 or laterOracle WebLogic Server, version 9.2 or laterOracle WebLogic Portal, version 10gR3IBM WebSphere Application Server, version 6.1 or laterIBM WebSphere Portal, version 6.1 and 7.0JBoss Application Server, version 3.2.8 or laterJetty, version 5 or laterGlassfish, version 2 or laterLiferay Portal 5.2 or laterGateIn Portal 3.1eXo Platform 3Google App Engine

Vaadin supports Java Servlet API 2.3 and JSR-168 and JSR-286 Portlet Specifications and should work with any Java application server that conforms to these standards.

Page 92: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

EclipseIntelliJ IDEA

NetbeansMaven

AntSpring Roo

∙ ∙ ∙

Page 93: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 94: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

mvn archetype:generate-DarchetypeGroupId=com.vaadin -DarchetypeArtifactId= vaadin-archetype-clean

Maven

yourproject-1.0.warmvn package

Page 95: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

gettingstarted

Page 96: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen
Page 97: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

vaadin.com/download

Page 98: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

vaadin.com/comparison

Page 99: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Download for Free

4th Edition

US $29.95

Vaadin is an open source Java framework for building modern web applications that look great, perform well and make you and

your users happy. http://vaadin.com/

2675387895299

ISBN 978-952-92-6753-890000

vaadin.com/book

674 pages

Page 100: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

By Marko Grönroos

ABOUT VAADIN

ww

w.d

zone

.co

m

G

et M

ore

Ref

card

z! V

isit

ref

card

z.co

m

#85

Getting Started with VaadinCONTENTS INCLUDE:�� About Vaadin�� Creating An Application�� Components �� Layout Components�� Themes�� Data Binding and more...

Vaadin is a server-side Ajax web application development framework that allows you to build web applications just like with traditional desktop frameworks, such as AWT or Swing. An application is built from user interface components contained hierarchically in layout components.

In the server-driven model, the application code runs on a server, while the actual user interaction is handled by a client-side engine running in the browser. The client-server communications and any client-side technologies, such as HTML and JavaScript, are invisible to the developer. As the client-side engine runs as JavaScript in the browser, there is no need to install plug-ins. Vaadin is released under the Apache License 2.0.

Figure 1: Vaadin Client-Server Architecture

If the built-in selection of components is not enough, you can develop new components with the Google Web Toolkit (GWT)

Figure 2: Architecture for Vaadin Applications

Hot Tip

You can get a reference to the application object from any component attached to the application with ��$!!����$� ���

Event ListenersIn the event-driven model, user interaction with user interface components triggers server-side events, which you can handle

Web BrowserClient-Side Engine

JavaWeb Server

VaadinUIComponents

YourJavaApplication

WebService

EJB

DB

Servlet Container

UserApplication

EventListener

DataModel

ApplicationThemes

ApplicationResources

DefaultTheme

FileResources

ExternalResources

Database

DataBinding

Inherits Events Changes

AJAX Requests

Inherits

UIComponent

JavaServlet

ApplicationClass

Web BrowserClient-Side Engine

brought to you by...

Page 101: Vaadin, Rich Web Apps in Server-Side Java without Plug-ins or JavaScript: Joonas Lehtinen

Expert servicesOnline support

TrainingTools

vaadin.com/pro

[email protected] vaadin.com/joonas

@joonaslehtinen#vaadin

Slides available onslideshare

Questions?Comments?

BetterResultsFaster