+ All Categories
Home > Documents > A new' way to program dynamic web applications

A new' way to program dynamic web applications

Date post: 15-May-2015
Category:
Upload: sampetruda
View: 627 times
Download: 0 times
Share this document with a friend
Popular Tags:
24
Almaden Services Research E. M. Maximilien, http://maximilien.org 5 July 2006 © 2006 IBM Corporation A ‘new’ way to program dynamic web applications E. M. (Max) Maximilien, http://maximilien.org
Transcript
Page 1: A new' way to program dynamic web applications

Almaden Services Research

E. M. Maximilien, http://maximilien.org 5 July 2006 © 2006 IBM Corporation

A ‘new’ way to program dynamic web applications

E. M. (Max) Maximilien,

http://maximilien.org

Page 2: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation2 E. M. Maximilien, http://maximilien.org 5 July 2006

Agenda

The past– Overview of typical AJAX development– Problems and opportunities

The present: Google Web Toolkit (GWT) – Architecture of a GWT project– Development cycle and tools – Widget UI library– Simple browser-to-server RPC– JavaScript native interface (JSNI)– Calling Web services– Deployment and other tricks

The good, the bad, and the uglyTerms, agreement, and licensing (IANAL)Other thoughts

Page 3: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation3 E. M. Maximilien, http://maximilien.org 5 July 2006

The past: typical AJAX web application development

AJAX – asynchronous JavaScript and XML– Client-side JavaScript (JS) to asynchronously fetch data– To dynamically modify client page using DOM API

Typical development stack– Java

• J2EE compatible server, e.g., Tomcat or WebSphere application server• Model View Controller (MVC) web application framework, e.g., Struts• Java Server Pages (JSP) templates, tag libraries, and scriptlets for Views

– Ruby• Similar except use Rails, RHTML, and JS libraries• RJS is an improvement (still in development)

– Embed JavaScript for AJAX functionality in JSP• JS libraries such as scriptalicious, prototype, effects, dojo, Yahoo! UI, and others

– Cascading Style Sheets (CSS) for View styling

Page 4: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation4 E. M. Maximilien, http://maximilien.org 5 July 2006

The past: problems and opportunities

Problems– Multiple languages and frameworks across stack– Mixing JS, JSP tags, Java, XML, and other config files leads to

• Maintenance nightmare• Less modularization• Less reusable code (Views) • Breaks MVC principles

– Complicated debugging and testing (different browsers)

Opportunities– Simplify AJAX web development with one language– Address maintenance, debugging, and modularization issues– Abstract client-side JS as browser assembly code!– The browser as another targeted “device”

Page 5: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation5 E. M. Maximilien, http://maximilien.org 5 July 2006

The present: Google Web Toolkit (GWT)

Java-to-JavaScript compilerShell to test and debug modules without compilationPartial JS emulated versions for JRE packages– java.lang.*– java.util.*

UI widget library (not AWT and not Swing)Simple asynchronous browser-to-server RPCDevelopment tools, e.g., applicationCreator, projectCreator, and junitCreator

Not new! Microsoft ASP.NET is similar and released years ago– However, limited to .NET and IE– Not sure of current status (likely more open)

Seaside (based on Squeak Smalltalk dialect) is a Smalltalk-based OO framework for coding web applicationsAny other similar compilers and frameworks for other languages?

Page 6: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation6 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: architecture of a GWT project (client side)

Project module, e.g., org.swashup.SwashupDesigner

JavaScript partial emulation of java.lang and java.util

gwt-user.jarUI widget and more

Your Java Code

GWTCompiler

Project.gwt.xml(module definition)

Your Java Code

Resources(e.g., GIF)

<<uses>>

Resources(e.g., GIF)

Project.html

JS

JS

JARs(modules, widgets)

Client-side UI

Limited to GWT UI

widgets and JRE subset

Page 7: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation7 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: architecture of a GWT project (server side)

AbcRemoteServiceXyzRemoteService.java

AbcRemoteServiceAsyncXyzRemoteServiceAsync.java

JavaScript partial emulation of java.lang and java.util

gwt-user.jarUI widget and more JARs

<project-package>.client

AbcRemoteServiceImp.java

XyzRemoteServiceImp.java

Not limited

<project-package>.server

Effectively servlets

web.xml

/WEB-INF/clases/*.class OR

/WEB-INF/lib/project.jar

WEB-INF/lib/*.jar

WAR for J2EE ORAutomatically done

for GWTShell (hosted-mode)

Page 8: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation8 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: development cycle and tools

Hosted-mode– GWTShell

– Quick code-test cycle

– Style with CSS

Web-mode– GWTCompiler

• Module (Java) compiled as JS and HTML– Style with CSS

– Deploy into J2EE compliant server

– Test using IE, FireFox, Safari, and Opera as client browser

Page 9: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation9 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: development and tools (cont.)

GWTShell

gwt-user.jar(JRE emulation and UI widget)

GWTCompiler

JARJAR

Page 10: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation10 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: package diagram

com.google.gwt.core.client

com.google.gwt.core.ext com.google.gwt.core.ext.typeinfo

com.google.gwt.core.junit.client

com.google.gwt.core.user.client

com.google.gwt.core.user.client.rpc

com.google.gwt.core.user.client.ui

com.google.gwt.core.user.server.rpc

Page 11: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation11 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: UI widget library, listeners, and otherWidgetsButton, CheckBox, TextBox, PasswordTextBox, TextArea, DialogBox, FlexTable, Label, ListBox, MenuBar, MenuItem, Tree, TreeItem, WidgetHTML, HTMLTable, Hyperlink

Composite to create custom composed widgetPanelsPanel, SimplePanel, VerticalPanel, HorizontalPanel, DockPanel, DeckPanel, PopupPanel, ScrollPanel, RootPanel

ListenersChangeListener, ClickListener, KeyboardLister, MouseListener, FocusListener, LoadListener, TreeListener, TabListener

Other interfacesEntryPoint, IsSerializable, RemoteService, AsyncCallback, Has<Xyz>, Sources<Xyz>Events

Other classesGWT, Window, History, Timer, Random, DOM, Cookies, JavaScriptObject, and others

ExceptionsInvocationException, SerializableException

Page 12: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation12 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: UI widget library, listeners, and other (cont.)

Page 13: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation13 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: UI widget library, listeners, and other (cont.)

Pictures from GWT web site: http://code.google.com/webtoolkit

Page 14: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation14 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: UI widget library, listeners, and other (cont.)

FlowPanel

DockPanel

VerticalPanel HorizontalPanel

Pictures from GWT web site: http://code.google.com/webtoolkit

Page 15: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation15 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: simple browser-to-server RPC mechanism<project-package>.client– XyzService interface

• Extends RemoteService• Can throw custom exception• Primitive types in signature• IsSerializable class parameters

– XyzServiceAsync interface• Matching service methods• Same signature but:

– Callback future object parameter– void return type

Model objects – Must implement IsSerializable– Use transient for non-serializablemembers

Restricted to JRE emulation subset

<<ajaxService>>SerenityService

+ login( name, pw, AsyncCallback cb ) : void+ logout ( name, AsyncCallback cb ): void

<<ajaxService>>AdminServiceAsync

<<exception>>ServiceException

<<throws>>

+ login( name, pw) : UserModel+ logout( name ): void

<<ajaxService>>AdminService

<<ajaxService>>RemoteService

+ onSuccess( Object ) void+ onFailure( Throwable ) : void

<<interface>>AsyncCallback

Page 16: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation16 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: simple browser-to-server RPC mechanism (cont.)

<project-package>.server

– XyzServiceImp class– Extends RemoteServiceServlet

No restrictions on importsMake call to back-end tiers– Web services– Databases

JAR dependencies– Add to GWTShell and GWTCompiler scripts

– Include in WAR file

+ login( name, pw) : UserModel+ logout( name ): void

<<ajaxService>>AdminService

<<servlet>>RemoteServiceServlet

<<servlet>>HttpServlet

+ login( name, pw) : UserModel+ logout( name ): void

AdminServiceImp

Page 17: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation17 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: simple browser-to-server RPC mechanism (cont.)

//Example client of AdminService.login

AdminServiceAsync adminAsync = getAdminServiceAsync();

//…

String name = nameTextBox.getText();

String password = passwordTextBox.getText();

adminAsync.login( name, password, new AsyncCallback() {

public void onSuccess( Object result ) {

UserModel user = (UserModel)result;

//Do post-login processing

}

public void onFailure( Throwable throwable ) {

//Process login failure

Window.alert( “Error login, invalid user name or password” );

}

});

Page 18: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation18 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: JavaScript native interface (JSNI)

Java native code extension– Use native keyword on method– Call Java methods and other JS code– Pass JS object (JavaScriptObject) to JavaExample:

public class Native{public static native void callNative()/*-{ $wnd.alert(“Hello from JavaScript!”); }-*/;

public native void callJavaNative()/*-{ [email protected].

Window::alert(Ljava/lang/String;)(“Hello called from JavaScript!”);}-*/

}

Customize generated widget codeFine-grained control over client JS

Page 19: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation19 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: calling web services (back-end)

Include web services (WS) proxies JARsDefine client model objectsCache (optional)– AJAX server cache – Browser client cache

Use browser-to-server RPC– Move data from server cache to client cache

– Browser-to-server RPC call equivalent to:•One WS call•Aggregate multiple WS calls

Page 20: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation20 E. M. Maximilien, http://maximilien.org 5 July 2006

GWT: deployment and other tricksGWTShell– Uses embedded version of Tomcat– Add dependency JARs in <Project>-compile and <Project>-shell scripts (generated by applicationCreator)

Deploying as WAR– Include gwt-user.jar– Include other JAR dependencies in WEB-INF/lib/– Include www/<project-module-directory>/* in WAR– Add RPC service entries in web.xml

Mix environment– Add JAR dependencies into WAR (as above)– Add <module> … </module> in JSP (or other) template header– Add RPC service entries in web.xml

Page 21: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation21 E. M. Maximilien, http://maximilien.org 5 July 2006

The good, the bad, and the uglyThe good– All things mentioned earlier– Java development tools, e.g., Eclipse, IDEAJ, and others– Excellent browser-to-server RPC– Performance seems on par with custom JS code– Ability to hand-craft JS code with JSNI

The bad– Layouts and panels and some widgets have bugs– Some limitations in JRE emulation– Issues running on Windows XP (not sure of details)

The ugly– No i18n or accessibility support– Browser compatibility pretty good but issues with some IE versions– Licensing terms and agreement – half OSS ☺ and half proprietary

Page 22: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation22 E. M. Maximilien, http://maximilien.org 5 July 2006

Terms, agreement, and licensing (IANAL)

Apache 2.0 license– UI widgets – Other libraries

No restrictions in generated code (no IP restrictions)Compiler, tools, and shell under different terms and agreementCannot repackage toolsShell “pings” home; although Google claims only for usage statistics and update purposes…What’s in it for Google?

Page 23: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation23 E. M. Maximilien, http://maximilien.org 5 July 2006

Other thoughts

GWT and the likes– Paradigm shift in web development– Unified and streamlined development– Needed if AJAX is to be widely successful

• Maintenance, debugging, development scalability, and so onThe browser as development client platformGWT is still at version 1.0.21– Expect more stable future versions– Better cross-browser support (better IE support)– Mac support– I18n and accessibility

Predict support for advance UI, i.e., drag-and-drop, animation, and so onPredict widget libraries on top of GWT by Google and third parties

Page 24: A new' way to program dynamic web applications

Almaden Services Research

© 2006 IBM Corporation24 E. M. Maximilien, http://maximilien.org 5 July 2006

Thank You

MerciGrazie

Gracias

Obrigado

Danke

Japanese

English

French

Russian

German

Italian

Spanish

Brazilian Portuguese

Arabic

Traditional Chinese

Simplified Chinese

Hindi

Tamil

Thai

Korean


Recommended