49
Simplify Web Development using JWt Koen Deforche February 7, 2010

Simplify Web Development using JWt

Embed Size (px)

Citation preview

Page 1: Simplify Web Development using JWt

Simplify Web Development using JWt

Koen Deforche

February 7, 2010

Page 2: Simplify Web Development using JWt

JWt in a nutshell

JWt takes away the pain of web application development

• Programming model resembles Swing (stateful)◦ Component-based (widgets)

• At the same time:◦ Interactive single page applications (AJAX)◦ Accessible multi page applications (plain HTML)◦ Using progressive enhancement

• Deployed as Java Servlet

First release (3.0.0), September ’09.Now: 3.1.0

2 of 28

Page 3: Simplify Web Development using JWt

JWt in a nutshell

JWt takes away the pain of web application development

• Programming model resembles Swing (stateful)◦ Component-based (widgets)

• At the same time:◦ Interactive single page applications (AJAX)◦ Accessible multi page applications (plain HTML)◦ Using progressive enhancement

• Deployed as Java Servlet

First release (3.0.0), September ’09.Now: 3.1.0

2 of 28

Page 4: Simplify Web Development using JWt

JWt in a nutshell

JWt takes away the pain of web application development

• Programming model resembles Swing (stateful)◦ Component-based (widgets)

• At the same time:◦ Interactive single page applications (AJAX)◦ Accessible multi page applications (plain HTML)◦ Using progressive enhancement

• Deployed as Java Servlet

First release (3.0.0), September ’09.Now: 3.1.0

2 of 28

Page 5: Simplify Web Development using JWt

JWt in a nutshell

JWt takes away the pain of web application development

• Programming model resembles Swing (stateful)◦ Component-based (widgets)

• At the same time:◦ Interactive single page applications (AJAX)◦ Accessible multi page applications (plain HTML)◦ Using progressive enhancement

• Deployed as Java Servlet

First release (3.0.0), September ’09.Now: 3.1.0

2 of 28

Page 6: Simplify Web Development using JWt

JWt in a nutshell

JWt takes away the pain of web application development

• Programming model resembles Swing (stateful)◦ Component-based (widgets)

• At the same time:◦ Interactive single page applications (AJAX)◦ Accessible multi page applications (plain HTML)◦ Using progressive enhancement

• Deployed as Java Servlet

First release (3.0.0), September ’09.Now: 3.1.0

2 of 28

Page 7: Simplify Web Development using JWt

Two approaches to web development

Web development: two diverging directions:

UI rendered @ server

• Multi-page

• Server-side frameworks

• Page-based MVC

• RESTful (clean) URLs

• AJAX for enhancements,effects

• e.g. PHP, Django, or Ruby

on Rails + jQuery or Dojo

UI rendered @ client

• Single-page

• JavaScript (DHTML)

• Widget-based MVC

• Backend provides RESTfulservices/RPC

• e.g. ExtJS, Capuccino, GWT,

Vaadin

3 of 28

Page 8: Simplify Web Development using JWt

Two approaches to web development

Web development: two diverging directions:

UI rendered @ server

• Multi-page

• Server-side frameworks

• Page-based MVC

• RESTful (clean) URLs

• AJAX for enhancements,effects

• e.g. PHP, Django, or Ruby

on Rails + jQuery or Dojo

UI rendered @ client

• Single-page

• JavaScript (DHTML)

• Widget-based MVC

• Backend provides RESTfulservices/RPC

• e.g. ExtJS, Capuccino, GWT,

Vaadin

3 of 28

Page 9: Simplify Web Development using JWt

Two approaches to web development

Web development: two diverging directions:

UI rendered @ server

• Multi-page

• Server-side frameworks

• Page-based MVC

• RESTful (clean) URLs

• AJAX for enhancements,effects

• e.g. PHP, Django, or Ruby

on Rails + jQuery or Dojo

UI rendered @ client

• Single-page

• JavaScript (DHTML)

• Widget-based MVC

• Backend provides RESTfulservices/RPC

• e.g. ExtJS, Capuccino, GWT,

Vaadin

3 of 28

Page 10: Simplify Web Development using JWt

Two approaches to web development

Web development: two diverging directions:

UI rendered @ server

• Multi-page

• Server-side frameworks

• Page-based MVC

• RESTful (clean) URLs

• AJAX for enhancements,effects

• e.g. PHP, Django, or Ruby

on Rails + jQuery or Dojo

UI rendered @ client

• Single-page

• JavaScript (DHTML)

• Widget-based MVC

• Backend provides RESTfulservices/RPC

• e.g. ExtJS, Capuccino, GWT,

Vaadin

3 of 28

Page 11: Simplify Web Development using JWt

Two approaches to web development

Web development: two diverging directions:

UI rendered @ server

• Multi-page

• Server-side frameworks

• Page-based MVC

• RESTful (clean) URLs

• AJAX for enhancements,effects

• e.g. PHP, Django, or Ruby

on Rails + jQuery or Dojo

UI rendered @ client

• Single-page

• JavaScript (DHTML)

• Widget-based MVC

• Backend provides RESTfulservices/RPC

• e.g. ExtJS, Capuccino, GWT,

Vaadin

3 of 28

Page 12: Simplify Web Development using JWt

Two approaches to web development

Web development: two diverging directions:

UI rendered @ server

• Multi-page

• Server-side frameworks

• Page-based MVC

• RESTful (clean) URLs

• AJAX for enhancements,effects

• e.g. PHP, Django, or Ruby

on Rails + jQuery or Dojo

UI rendered @ client

• Single-page

• JavaScript (DHTML)

• Widget-based MVC

• Backend provides RESTfulservices/RPC

• e.g. ExtJS, Capuccino, GWT,

Vaadin

3 of 28

Page 13: Simplify Web Development using JWt

Two approaches to web development

Web development: two diverging directions:

UI rendered @ server

• Multi-page

• Server-side frameworks

• Page-based MVC

• RESTful (clean) URLs

• AJAX for enhancements,effects

• e.g. PHP, Django, or Ruby

on Rails + jQuery or Dojo

UI rendered @ client

• Single-page

• JavaScript (DHTML)

• Widget-based MVC

• Backend provides RESTfulservices/RPC

• e.g. ExtJS, Capuccino, GWT,

Vaadin

3 of 28

Page 14: Simplify Web Development using JWt

Server-side rendering

Benefits:

• Does not rely on JavaScript◦ URLs can be indexed by search bots◦ Accessible◦ JavaScript for enhancements

• Data sources are not exposed

• Fast load time

4 of 28

Page 15: Simplify Web Development using JWt

Client-side rendering

Benefits:

• Highly interactive applications◦ taking the server out of the loop: 130 ms → 0 ms

• Widget based MVC → reusable code

• Long running interactivity (e.g. chat functionality)

Drawbacks:

• Manage the communication (chosing between REST or RPC).

• All the head-aches of client-server programming

• Slow load time◦ JavaScript download + parse

5 of 28

Page 16: Simplify Web Development using JWt

Client-side rendering

Benefits:

• Highly interactive applications◦ taking the server out of the loop: 130 ms → 0 ms

• Widget based MVC → reusable code

• Long running interactivity (e.g. chat functionality)

Drawbacks:

• Manage the communication (chosing between REST or RPC).

• All the head-aches of client-server programming

• Slow load time◦ JavaScript download + parse

5 of 28

Page 17: Simplify Web Development using JWt

Client-side rendering: REST or RPC ?

REST:

• Define services for simple (low-level) operations

• Services independent of application complexity and state

• A single event may cause several RESTful updates (slow!)

• And what about transactions ?

RPC:

• Define services for handling particular events

• Services depends on application complexity and state

• A single event will usually cause only one RPC call (fast!)

6 of 28

Page 18: Simplify Web Development using JWt

Client-side rendering: REST or RPC ?

REST:

• Define services for simple (low-level) operations

• Services independent of application complexity and state

• A single event may cause several RESTful updates (slow!)

• And what about transactions ?

RPC:

• Define services for handling particular events

• Services depends on application complexity and state

• A single event will usually cause only one RPC call (fast!)

6 of 28

Page 19: Simplify Web Development using JWt

Client-side rendering: REST or RPC ?

REST:

• Define services for simple (low-level) operations

• Services independent of application complexity and state

• A single event may cause several RESTful updates (slow!)

• And what about transactions ?

RPC:

• Define services for handling particular events

• Services depends on application complexity and state

• A single event will usually cause only one RPC call (fast!)

6 of 28

Page 20: Simplify Web Development using JWt

Client-side rendering: REST or RPC ?

REST:

• Define services for simple (low-level) operations

• Services independent of application complexity and state

• A single event may cause several RESTful updates (slow!)

• And what about transactions ?

RPC:

• Define services for handling particular events

• Services depends on application complexity and state

• A single event will usually cause only one RPC call (fast!)

6 of 28

Page 21: Simplify Web Development using JWt

Client-side rendering: REST or RPC ?

REST:

• Define services for simple (low-level) operations

• Services independent of application complexity and state

• A single event may cause several RESTful updates (slow!)

• And what about transactions ?

RPC:

• Define services for handling particular events

• Services depends on application complexity and state

• A single event will usually cause only one RPC call (fast!)

6 of 28

Page 22: Simplify Web Development using JWt

A slow web application is a slow application

(it’s usually not the web that is slow)

7 of 28

Page 23: Simplify Web Development using JWt

JWt’s rendering model

• Stateful, widget-based◦ Truly reusable components◦ Separate View and Model anyway you like◦ Signals implement Observable pattern

• Rendered server-side◦ As plain HTML◦ Or as AJAX updates◦ Progressive enhancement

• Internal paths◦ http://glorio.us/app/user/kdf/settings (plain HTML)◦ http://glorio.us/app#/user/kdf/settings (AJAX)

8 of 28

Page 24: Simplify Web Development using JWt

JWt’s rendering model

• Stateful, widget-based◦ Truly reusable components◦ Separate View and Model anyway you like◦ Signals implement Observable pattern

• Rendered server-side◦ As plain HTML◦ Or as AJAX updates◦ Progressive enhancement

• Internal paths◦ http://glorio.us/app/user/kdf/settings (plain HTML)◦ http://glorio.us/app#/user/kdf/settings (AJAX)

8 of 28

Page 25: Simplify Web Development using JWt

JWt’s rendering model

• Stateful, widget-based◦ Truly reusable components◦ Separate View and Model anyway you like◦ Signals implement Observable pattern

• Rendered server-side◦ As plain HTML◦ Or as AJAX updates◦ Progressive enhancement

• Internal paths◦ http://glorio.us/app/user/kdf/settings (plain HTML)◦ http://glorio.us/app#/user/kdf/settings (AJAX)

8 of 28

Page 26: Simplify Web Development using JWt

Example: hello world

public class HelloMain extends WtServlet {

public HelloMain() {

getConfiguration().setProgressiveBootstrap(true);

}

@Override

public WApplication createApplication(WEnvironment env) {

return new HelloApplication(env);

}

}

9 of 28

Page 27: Simplify Web Development using JWt

Example: hello world

public class HelloMain extends WtServlet {

public HelloMain() {

getConfiguration().setProgressiveBootstrap(true);

}

@Override

public WApplication createApplication(WEnvironment env) {

return new HelloApplication(env);

}

}

9 of 28

Page 28: Simplify Web Development using JWt

Example: hello world

public class HelloApplication extends WApplication {

private WLineEdit nameEdit;

private WText greeting;

public HelloApplication(WEnvironment env) {

super(env); setTitle("Hello world");

new WText("Your name, please ? ", getRoot());

nameEdit = new WLineEdit(getRoot());

nameEdit.setFocus();

WPushButton button = new WPushButton("Greet me.", getRoot());

greeting = new WText(getRoot());

button.clicked().addListener(this, new Signal.Listener() {

public void trigger() {

greeting.setText("Hello there, " + nameEdit.getText());

}

});

}

}10 of 28

Page 29: Simplify Web Development using JWt

Hello world: plain HTML

11 of 28

Page 30: Simplify Web Development using JWt

Hello world: AJAX

12 of 28

Page 31: Simplify Web Development using JWt

Hello world: behind the scenes

• Automatic propagation of form values

• XSS mitigation

• smart AJAX RPC handling:◦ automatic propagation of widget changes◦ changes to visible widgets are propagated first◦ changes to hidden widgets in a second request in background

13 of 28

Page 32: Simplify Web Development using JWt

Some selected features

• Signals and listeners

• Layout

• Web graphics API

• Rich widgets

• Hybrid validators

• Security

• Internal paths

14 of 28

Page 33: Simplify Web Development using JWt

Signals and listeners: observer pattern

public class AlarmModel {

public Signal2<Integer, String> fired;

private void fireAlarm() {

fired.trigger(42, "Alarma !!");

}

}

public class AlarmView extends WText {

public AlarmView(AlarmModel model) {

model.fired.addListener(this, new Signal2.Listener<Integer, String>() {

void trigger(Integer code, String distress) {

setText(distress);

}

});

}

}

15 of 28

Page 34: Simplify Web Development using JWt

Signals and listeners: observer pattern

• Automatic connection management◦ Protects against memory leaks◦ Uing java.lang.ref.WeakReference and scopes listeners

implemented by anonymous inner classes.

• Signal: for user code

• EventSignal: signals standard DOM events◦ EventSignal1<WMouseEvent> clicked()◦ EventSignal1<WKeyEvent> keyWentDown()◦ Only clicked() events are propagated in plain HTML

• JSignal: can be emitted from user JavaScript code

16 of 28

Page 35: Simplify Web Development using JWt

Layout

JWt offers two options:

• CSS◦ Well-suited for public applications (accessible)◦ Web page like user interfaces◦ Limited vertical layout possibilities◦ Use WTemplate to separate layout from logic

• Layout managers◦ Uses JavaScript to fix deficiencies in CSS◦ Application-like user interface◦ WBoxLayout, WGridLayout, WBorderLayout

17 of 28

Page 36: Simplify Web Development using JWt

Web graphics API

JWt provides a painting API with four backends:

• HTML5 <canvas> (JavaScript)

• SVG, rendering inline as application/xhtml+xml

• VML (for IE browsers)

• PNG (using java.awt.Graphics2D)

This is used in the included charting library.

18 of 28

Page 37: Simplify Web Development using JWt

Rich widgets: chart widgets

19 of 28

Page 38: Simplify Web Development using JWt

Rich widgets: WTreeView

20 of 28

Page 39: Simplify Web Development using JWt

Rich widgets: WTabWidget

(polished theme)

(default theme)

21 of 28

Page 40: Simplify Web Development using JWt

Rich widgets: WDatePicker

22 of 28

Page 41: Simplify Web Development using JWt

Rich widgets: WPopupMenu

23 of 28

Page 42: Simplify Web Development using JWt

Rich widgets: WSuggestionPopup

24 of 28

Page 43: Simplify Web Development using JWt

Hybrid validators

Validators with hybrid implementations:

• Client-side: direct feed-back

• Server-side: trusted validation

Custom validators with hybrid implementations: when based onWRegExpValidator

25 of 28

Page 44: Simplify Web Development using JWt

Security

Built-in prevention of most common web vulnerabilities:

• XSS prevention on output (WText)

• not vulnerable to CSRF (no cookies for session tracking)

• application logic (sequencing)

26 of 28

Page 45: Simplify Web Development using JWt

Internal paths

• Internal paths are abstractions of URLs internal to the application.◦ void setInternalPath()◦ Signal<String> internalPathChanged() signal

• They are rendered in two forms:◦ Using path-info (portable, plain HTML sessions)◦ Using a URL fragment (AJAX, single page interfaces)

• WAnchor:◦ presents portable URL◦ catches click to use URL fragment

27 of 28

Page 46: Simplify Web Development using JWt

Conclusion

JWt for web applications:

• A mature library◦ Wt, its C++ sibling has been around for over five years◦ latest version: 3.1.0

• Unique rendering model◦ benefits of client-side rendering (AJAX)◦ benefits of server-side rendering (accessibility)

• Feature complete◦ not only widgets but also graphics API, l10n, validators, ...

More information at http://www.webtoolkit.eu/jwt/

28 of 28

Page 47: Simplify Web Development using JWt

Conclusion

JWt for web applications:

• A mature library◦ Wt, its C++ sibling has been around for over five years◦ latest version: 3.1.0

• Unique rendering model◦ benefits of client-side rendering (AJAX)◦ benefits of server-side rendering (accessibility)

• Feature complete◦ not only widgets but also graphics API, l10n, validators, ...

More information at http://www.webtoolkit.eu/jwt/

28 of 28

Page 48: Simplify Web Development using JWt

Conclusion

JWt for web applications:

• A mature library◦ Wt, its C++ sibling has been around for over five years◦ latest version: 3.1.0

• Unique rendering model◦ benefits of client-side rendering (AJAX)◦ benefits of server-side rendering (accessibility)

• Feature complete◦ not only widgets but also graphics API, l10n, validators, ...

More information at http://www.webtoolkit.eu/jwt/

28 of 28

Page 49: Simplify Web Development using JWt

Conclusion

JWt for web applications:

• A mature library◦ Wt, its C++ sibling has been around for over five years◦ latest version: 3.1.0

• Unique rendering model◦ benefits of client-side rendering (AJAX)◦ benefits of server-side rendering (accessibility)

• Feature complete◦ not only widgets but also graphics API, l10n, validators, ...

More information at http://www.webtoolkit.eu/jwt/

28 of 28