rich web applications in server-side java without plug-ins...

87
Joonas Lehtinen, PhD Vaadin Ltd - CEO [email protected] Rich Web Applications in Server-side Java without Plug-ins or JavaScript twitter: #vaadin @joonaslehtinen

Upload: others

Post on 22-May-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Joonas Lehtinen, PhDVaadin Ltd - CEO

[email protected]

Rich Web Applications in Server-side Java without

Plug-ins or JavaScripttwitter: #vaadin @

joonaslehtinen

Page 2: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

?

Page 3: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 4: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Vaadin is a UI framework for desktop-like web

apps

Page 5: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Vaadin is a UI framework for desktop-like web

apps

Page 6: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

New configs, taglibs and syntax!?!

JavaScript,DOM, Applet,plugins?

This is Java. Nothing else.{No!

Page 7: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

htmljava

Page 8: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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

1998

Page 9: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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

Page 10: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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

Page 11: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

object oriented design, desktop, Java, U and I ... desktop programming paradigm for web! found

Page 12: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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

2000

2002

2005

2008

Page 13: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

millstone ajax goolge web toolkit re-released as

2009

Page 14: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Vaadin is now 21 months young and 10 years old

Page 15: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

ApacheLicense

Page 16: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Discussion

VaadinBig picture, Extending, Getting started

Server-side RIAWhat is it? Pros & cons?

In practiceCoding a Vaadin application step-by-step

Contents

Page 17: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Server-side RIA

Page 18: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

?Rich Internet Application

Page 19: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

application that makes developers rich

Page 20: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

if they bill by hour

Page 21: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Architecture

Page 22: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

“Web 1.0”

DOM

Client Server

ViewHTML Page

over HttpResponse

Controller

Model

Parameters overHttpRequest

DB2

3

4

5

1

Page 23: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

client-side ria

fat client

Page 24: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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 25: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

challengeweb is

not easy

Page 26: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

different featuresin different browsers

Page 27: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

different performancein different browsers

Page 28: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

different bugsin different browsers

Page 29: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Google Web Toolkit

Page 30: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Java toJavaScriptCompiler

Subset of

java.lang, java.util

Widgetset

Your Application UI

IE6

IE7

Firefox

Safari

Page 31: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

simpler• Java only• forget the web

Page 32: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

cost-effective stop debugging JavaScript spaghetti

Page 33: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

modularextensible♲

Page 34: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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

Page 35: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

server-side ria

thin client

Page 36: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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

Page 37: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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 38: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Java

modularextensible

cost-effectiveno JavaScript debugging

simplerforget the web

the benefits of Java

Page 39: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

even simpler• forget the client-side • synchronous• server resources

Page 40: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

more flexible• all Java tools and libraries• any JVM language

Page 41: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

more flexible• all Java tools and libraries• any JVM languageScala GroovyClojure

Page 42: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

more secure• code stays in server• less web services

Page 43: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

not as scalableUI state is stored in the server memory

Page 44: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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 45: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

no offline modeserver is always required

Page 46: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

#1 benefitdevelopmentis really fast

Page 47: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Seeing is believing

© National Geographic Channel 2010

Page 48: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

What we can do in 15 minutes?

Page 49: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 50: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 51: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Vaadin Framework

Page 52: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

1Great UI Components

Page 53: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 54: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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

Page 55: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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 56: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Creating new UI components is really easy

Page 57: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 58: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

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 59: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 60: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 61: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 62: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 63: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 64: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 65: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 66: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 67: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

3First classJava citizen

Page 68: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

Servlet Portlet

App Engine

Page 69: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

EclipseMaven

NetbeansSpring Roo

Page 70: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

gettingstarted

Page 71: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 72: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

By Marko Grönroos

ABOUT VAADIN

w

ww

.dzo

ne.c

om

Get

Mo

re R

efca

rdz!

Vis

it r

efca

rdz.

com

#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)

in Java.

An application that uses the Vaadin framework needs to inherit

class and implement the

CREATING AN APPLICATION

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 Listeners

In the event-driven model, user interaction with user interface

components triggers server-side events, which you can handle

with event listeners.

In the example below, we handle click events for a button with

an anonymous class:

Web BrowserClient-Side

Engine

JavaWeb Server

VaadinUIComponents

YourJavaApplication

WebService

EJB

DB

Servlet Container

UserApplication

EventListener

DataModel

Application

ThemesApplication

Resources

DefaultTheme

FileResources

ExternalResources

Database

DataBinding

Inherits Events Changes

AJAX Requests

Inherits

UIComponent

JavaServlet

Application

Class

Web BrowserClient-Side

Engine

brought to you by...

Vaadin 6.4 Edition

Page 73: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

www.vaadin.comMap Overlay Nov 14, 2009 - Nov 13, 2010

Comparing to: Site

Visits1 102,776

799,821 visits came from 196 countries/territoriesSite Usage

Visits799,821% of Site Total: 100.00%

Pages/Visit5.58Site Avg: 5.58 (0.00%)

Avg. Time on Site00:06:53Site Avg: 00:06:53 (0.00%)

% New Visits34.64%Site Avg: 34.53% (0.32%)

Bounce Rate37.55%Site Avg: 37.55% (0.00%)

Country/Territory Visits Pages/Visit Avg. Time onSite

% New Visits Bounce Rate

United States 102,776 5.49 00:06:41 42.29% 39.51%

Finland 84,139 6.58 00:07:48 18.89% 35.29%

Germany 73,722 5.80 00:06:26 33.97% 38.19%

France 32,840 5.86 00:06:43 37.86% 35.90%

India 30,822 4.48 00:06:35 51.93% 44.48%

United Kingdom 29,735 5.55 00:06:21 33.64% 41.84%

Russia 29,402 6.01 00:07:07 24.38% 33.45%

Italy 27,904 5.96 00:06:36 34.25% 35.30%

Brazil 24,071 5.17 00:07:13 40.93% 35.94%

1 Google Analytics

Ask the[really active, world wide]

Community

Forums with1500 msgs/m

Page 74: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

PRODUCTIVITY

Page 75: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 76: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

persistence setup --provider HIBERNATE--database HYPERSONIC_IN_MEMORY

entity --class ~.domain.Toppingfield string --fieldName name --notNull

entity --class ~.domain.Pizzafield number --fieldName price--type java.lang.Float

field set --fieldName toppings--type ~.domain.Topping

Page 77: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 78: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 79: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

vaadin setup --applicationPackage ~.web--baseName PizzaShop--themeName pizza--useJpaContainer false

vaadin generate all --package ~.web.ui --visuallyComposable true

Page 80: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 81: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 82: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 83: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 84: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers
Page 85: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers

field string --class ~.domain.Pizza --notNull --fieldName name --sizeMin 3

Page 86: Rich Web Applications in Server-side Java without Plug-ins ...assets.en.oreilly.com/1/event/61/Vaadin, Rich Web... · Rich Internet ? Application. application that makes developers