AJAX and jmaki for Web 2.0 Development using Java. Inyoung Cho Java Technology Evangelist Sun Microsystems, Inc.



Similar documents
An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

Performance Testing for Ajax Applications

Credits: Some of the slides are based on material adapted from

Preface. Motivation for this Book

Rich-Internet Anwendungen auf Basis von ColdFusion und Ajax

Google Web Toolkit. Progetto di Applicazioni Software a.a. 2011/12. Massimo Mecella

Term Paper. P r o f. D r. E d u a r d H e i n d l. H o c h s c h u l e F u r t w a n g e n U n i v e r s i t y. P r e s e n t e d T o :

AJAX. Gregorio López López Juan Francisco López Panea

Rich User Interfaces for Web-Based Corporate Applications

How To Write An Ria Application

Client-side Web Engineering From HTML to AJAX

Whitepaper. Rich Internet Applications. Frameworks Evaluation. Document reference: TSL-SES-WP0001 Januar

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Google Web Toolkit (GWT) Architectural Impact on Enterprise Web Application

CrownPeak Java Web Hosting. Version 0.20

Why AJAX? Keywords - Web applications, Java Script, Web INTRODUCTION. Why Not AJAX? 111 P a g e

Eclipse Web Tools Platform. Naci Dai (Eteration), WTP JST Lead

AJAX Toolkit Framework

IBM Rational Web Developer for WebSphere Software Version 6.0

Google Web Toolkit. Introduction to GWT Development. Ilkka Rinne & Sampo Savolainen / Spatineo Oy

Integration the Web 2.0 way. Florian Daniel April 28, 2009

White Paper. JavaServer Faces, Graphical Components from Theory to Practice

Web Development with the Eclipse Platform

Load Testing RIA using WebLOAD. Amir Shoval, VP Product Management

ArcGIS Server mashups

Advantage of Jquery: T his file is downloaded from

What s New in IBM Web Experience Factory IBM Corporation

GUI and Web Programming

How To Write A Web Server In Javascript

Java in Web 2.0. Alexis Roos Principal Field Technologist, CTO Office OEM SW Sales Sun Microsystems, Inc.

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

Web application development landscape: technologies and models

NetBeans IDE Field Guide

XML Processing and Web Services. Chapter 17

YouTrack MPS case study

<Insert Picture Here> Betting Big on JavaServer Faces: Components, Tools, and Tricks

WA 2. GWT Martin Klíma

Introduction to BlackBerry Smartphone Web Development Widgets

Web Application Development

Application layer Web 2.0

RIA Technologies Comparison

Programming Fundamentals of Web Applications Course 10958A; 5 Days

Software Development Interactief Centrum voor gerichte Training en Studie Edisonweg 14c, 1821 BN Alkmaar T:

Adding Panoramas to Google Maps Using Ajax

Performance Testing Web 2.0. Stuart Moncrieff (Load Testing Guru) /

Introduction to web development and JavaScript

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

AJAX and JSON Lessons Learned. Jim Riecken, Senior Software Engineer, Blackboard Inc.

Accessing Data with ADOBE FLEX 4.6

Core Ideas CHAPTER 1 PART. CHAPTER 2 Pre-Ajax JavaScript Communications Techniques CHAPTER 3 XMLHttpRequest Object CHAPTER 4 Data Formats

Distance Examination using Ajax to Reduce Web Server Load and Student s Data Transfer

Developing ASP.NET MVC 4 Web Applications MOC 20486

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

The Oracle Fusion Development Platform

Rapid Application Development. and Application Generation Tools. Walter Knesel

Unlocking the Java EE Platform with HTML 5

Visual WebGui for ASP.NET Ajax (and other Ajax) Web Developers Learn what makes Visual WebGui not just another Ajax framework

Ajax Development with ASP.NET 2.0

Building and Using Web Services With JDeveloper 11g

Chapter 12: Advanced topic Web 2.0

Category: Business Process and Integration Solution for Small Business and the Enterprise

MO 25. Aug. 2008, 17:00 UHR RICH INTERNET APPLICATIONS MEHR BISS FÜR WEBANWENDUNGEN

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Transition your MCPD Web Developer Skills to MCPD ASP.NET Developer 3.5 (VB)

Progressive Enhancement With GQuery and GWT. Ray Cromwell

Developing ASP.NET MVC 4 Web Applications

4.2 Understand Microsoft ASP.NET Web Application Development

Developer Tutorial Version 1. 0 February 2015

Web Design Specialist

Lucy Zhang UI Developer Contact:

IBM Script Portlet for WebSphere Portal Release 1.1

Performance Testing Web 2.0

A Tool for Evaluation and Optimization of Web Application Performance

Enabling AJAX in ASP.NET with No Code

Position Paper: Toward a Mobile Rich Web Application Mobile AJAX and Mobile Web 2.0

Building Rich Internet Applications with PHP and Zend Framework

IBM Digital Experience. Using Modern Web Development Tools and Technology with IBM Digital Experience

An Esri White Paper October 2010 Developing with Esri Business Analyst Server

Web Cloud Architecture

Reporting and JSF. Possibilities, solutions, challenges. Slide 1. Copyright 2009, Andy Bosch,

Oracle Application Development Framework Overview

Enhancing your Web Experiences with ASP.NET Ajax and IIS 7

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

Outline. CIW Web Design Specialist. Course Content

Course Information Course Number: IWT 1229 Course Name: Web Development and Design Foundation

HTML5. Turn this page to see Quick Guide of CTTC

AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

J j enterpririse. Oracle Application Express 3. Develop Native Oracle database-centric web applications quickly and easily with Oracle APEX

SUBJECT CODE : 4074 PERIODS/WEEK : 4 PERIODS/ SEMESTER : 72 CREDIT : 4 TIME SCHEDULE UNIT TOPIC PERIODS 1. INTERNET FUNDAMENTALS & HTML Test 1

Take full advantage of IBM s IDEs for end- to- end mobile development

Modern Web Application Framework Python, SQL Alchemy, Jinja2 & Flask


Pentesting Web Frameworks (preview of next year's SEC642 update)

ASP.NET: THE NEW PARADIGM FOR WEB APPLICATION DEVELOPMENT

SOA REFERENCE ARCHITECTURE: WEB TIER

It is highly recommended that you are familiar with HTML and JavaScript before attempting this tutorial.

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

Server-side OSGi with Apache Sling. Felix Meschberger Day Management AG 124

Overview. In the beginning. Issues with Client Side Scripting What is JavaScript? Syntax and the Document Object Model Moving forward with JavaScript

Rich Internet Applications

Transcription:

AJAX and jmaki for Web 2.0 Development using Java Inyoung Cho Java Technology Evangelist Sun Microsystems, Inc.

Agenda AJAX Basics > What is AJAX? > AJAX Interaction:Using AutoComplete Sample Application > JSON > AJAX Guidelines Jmaki AJAX Toolkits and Frameworks Summary and Resources

AJAX Basics: What is AJAX?

What is AJAX? AJAX is an acronym for Asynchronous Javascript And XML > AJAX uses JavaScript combined with xml to grab information from a server without refreshing the page > nothing new, the main requirement is the web browser has the support for XMLHttpRequest object > The term AJAX was coined Jesse James Garrett in February 2005 Asynchronous communication replaces "synchronous request/response model." > A user can continue to use the application while the client program requests information from the server in the background > Separation of displaying from data fetching

Why AJAX? "Partial screen update" replaces the "click, wait, and refresh" user interaction model > Only user interface elements that contain new information are updated (fast response) > The rest of the user interface remains displayed without interruption (no loss of operational context) Intuitive and natural user interaction > No clicking required > Mouse movement is a sufficient event trigger Data-driven (as opposed to page-driven) > UI is handled in the client while the server provides data

User Interface: Traditional Web vs. AJAX Interrupted user operation while the data is being fetched Uninterrupted user operation while data is being fetched

Components: Traditional Web vs. AJAX

AJAX Basics: AJAX Interaction: Using AutoComplete Sample Application

AutoComplete Using a Servlet How can you provide a better means of navigating a large set of data based on a search query?

Steps of An AJAX Interaction 1. A client event occurs. 2. An XMLHttpRequest object is created and configured. 3. The XMLHttpRequest object makes a call. 4. The request is processed by the AutocompleteServlet. 5. The AutocompleteServlet returns an XML document containing the result. 6. The XMLHttpRequest object calls the callback() function and processes the result. 7. The HTML DOM is updated.

AutoComplete Update

AJAX Applicaiton Demo Use various real life apps

AJAX Basics: JSON(Java Java Script Object Notation)

AJAX vs Ajax Not always XMLHTTPRequest > Comet, JSONP, IFRAME, Flash/Applet Not always XML > JSON, JavaScript, HTML, Plain text Not only JavaScript JSON, JavaScript, HTML, Plain text SVG / VML / dojo.gfx Behaviour Fancy transitions / Effects / DnD Mashups

JSON (Java Script Object Notation) object = { 'key' : value} array = [ value1, value2] value = string, number, object, array, true, false, null

Example: XML and JSON Category XML <category id="0" name="vegetables"> <products> <product><name>onion</name><price>.75</price></product> <product><name>carrot</name><price>.50</price></product> </products> </category> Category JSON {"id": "0", "name":"vegetables", "products": [ {"name": "Onion", "price":.75}, {"name": "Eggplant", "price":1.50} ] }

JavaScript to Parse the XML var categories = []; function processresults(responsexml) { } var categoryelements = responsexml.getelementsbytagname("category"); for (var l=0; l < categoryelements.length; l++) { } var categoryelement = categoryelements[l]; var catid = categoryelement.getattribute("id"); var catname = categoryelement.getattribute("name"); var cat = {id: catid, name: catname, products : []}; var ps = categoryelement.getelementsbytagname("product"); for (var pl=0; pl < ps.length; pl++) { } var name = ps[pl].getelementsbytagname("name")[0].firstchild.nodevalue; var price = ps[pl].getelementsbytagname("price")[0].firstchild.nodevalue; cat.products.push({productname: name, productprice: price}); categories.push(category); var veggies = categories[0].products[0];

Parsing JSON Responses var jsontext = // get the JSON text listed above var categories = eval("("jsontext")"); var veggies = categories[0].products[0];

AJAX Basics: AJAX Guidelines

AJAX Guidelines Usability JavaScript Libraries I18n State Management HTTP methods Return content-types Tools and Debuggers

Usability Back/Forward button meaningless Refresh button can kill your app > Save state in <body onload> method Bookmarking/URL sharing not working Printing dynamically rendered pages can be problematic JavaScript framework Dojo toolkit (http://dojotoolkit.org) > provides API's history manipulation and navigation control > provides client-side for bookmarking and URL manipulation Requires thinking about interface and interaction > Usability is the key > Do not break what the user is focusing on > Make sure to give the user feedback > Do not over-use it Recommendation: Consider the meaning of each and weigh the benefits when designing your application.

JavaScript Libraries There are differences in javascript implementations Serializing complex data and mapping it to javascript isn't a trival task Directly consuming xml in Javascript can be painful due to browser differences in technologies like xslt Dojo: a key focus on user experience Prototype: focuses more on AJAX interactions > JavaScript objects and utility methods DWR: both client-side and server-side framework > do RPC calls from client-side JavaScript to Java objects in a web container server side Recommendation: Adopt a library and don't try to re-invent the wheel.

Internationalization (I18n) Page Content Type <meta http-equiv="content-type" content="text/html; charset=utf-8"> Use JavaScript encodeuri() when building URLs or sending localizable content. Call HttpServletRequest.setCharacterEncoding("UTF-8") before retrieving any parameters from Java EE Recommendation: Use UTF-8 since it supports the widest number of languages and browsers.

Recommendation: Consider keeping non-secure state related to the rendering of the client on the client. Keep secure persistent state on the server. State Management On Client > In memory in JavaScript Objects > In hidden form variables > In cookies On Server > HttpSession > Persisted How do you handle state + sessions? > Can all be on the client so you can have truly stateless servers? > What happens if the server or network dies?

HTTP Methods GET > When the data will not change POST > When operation has side-effects and changes the state on the server. Recommendation: Follow the HTTP idempotency rules.

Response Content Type XML Text > Post processing on client > Inject directly into the page JavaScript > Evaluated in JavaScript using eval() > JavaScript object representations of data(json) Recommendation: Use XML for structured portable data. Use plain text for when injecting content into the HTML. Use JavaScript to return object representations data.

Development Tools for NetBeans IDE Building AJAX Applications over NetBeans is not that much different from building regular Web applications NetBeans JavaScript editor plug-in > http://www.liguorien.com/jseditor/

Debuggers Mozilla FireBug debugger (add-on) > This is the most comprehensive and most useful JavaScript debugger > This tool does things all other tools do and more Mozilla JavaScript console Mozilla DOM inspector (comes with Firefox package) Mozilla Venkman JavaScript debugger (add-on) Mozilla LiveHTTPHeaders HTTP monitor (similar to NetBeans HTTP monitor) Microsoft Script Debugger (IE specific)

jmaki Toolkit

Motivations for jmaki You want to leverage widgets from existing and future AJAX toolkits and frameworks > Dojo, Scriptaculus, Yahoo UI Widgets and DHTML Goodies Today, there are multiple AJAX frameworks with their own widgets and with different syntax > There is a need for a common programming model to these various widgets Too much of JavaScript code required for Java developers > There is a need for Java Language view of JavaScript-based widgets

Why jmaki? Project jmaki makes it easier to use popular AJAX frameworks within the Java EE Platform It provides a base set of wrappers around some of the widgets from the more popular frameworks (such as Dojo, Prototype and Yahoo Widgets) Project jmaki is easily extensible, allowing developers to use the latest and most useful widgets as they appear

Why jmaki? (cont.) Enables Java developers to use JavaScript in their Java based applications as either a JSP tag library or a JavaServer Faces component Uses the best parts of Java and the best parts of JavaScript to deliver a rich AJAX style widgets Promotes a program methodology that cleanly separates behavior (JavaScript), from Styles (CSS), from template HTML

jmaki Widgets from NetBeans 5 Plug-in

Usage Example of jmaki Widget (List) in a JSP page <%@ taglib prefix="a" uri="http://java.sun.com/jmaki" %> Declare JMaki Tag Lib <%@ taglib prefix="a" uri="http://java.sun.com/jmaki" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>jsp Page</title> </head> <body> <h1>jsp Page</h1> <a:ajax name="list" service="listservice.jsp" /> </body> </html> Place a jmaki Widget

HTML that is Rendered by jmaki <html>... <body> <script type="text/javascript" src="http://localhost:8080/jmakilist/jmaki.js"></script> <script type="text/javascript">jmaki.webroot='http://localhost:8080/jmakilist';</script> <link rel="stylesheet" type="text/css" href="http://localhost:8080/jmakilist/resources/list/component.css"></link> <div id="list0" class="listcontainer"> <form onsubmit="jmaki.attributes.get('list0').submitdata(); return false;"> <input id="list0_entryfield" type="text" size="20" value="enter new Value"> CSS <input type="button" onclick="jmaki.attributes.get('list0').submitdata(); return false;" value="add to List"></from> <div id="list0_list" class="listdiv"></div> </div> <script type="text/javascript"> HTML jmaki.addwidget ({service:'listservice.jsp',script:'http://localhost:8080/jmakilist/resources/list/component.js',uuid:'list0', name:'list'});</script> </body> JavaScript

How Does jmaki Know Which HTML Template to use for Rendering? jmaki (actually jmaki tag handler) takes the value from the name attribute - list in the example below > <a:ajax name="list" service="listservice.jsp" /> jmaki then finds the widget named as list list widget has the following 3 files associated with it - these files are parameterized > HTML template: list/component.html > CSS template: list/component.css > JavaScript code: list/component.js When rendered, the parameters are set with values

What Makes Up a jmaki Widget? HTML template Defines the page layout JavaScript file Defines behavior CSS file Defines style

jmaki: Pros and Cons Pros > Provides unified programming model for using widgets over various AJAX toolkits and frameworks > Allows Java developers to use familiar Java EE programming model (JSP or Faces tags) for using JavaScript widgets > There is already a NetBeans Plug-in Cons > Event model is still not fully baked yet When to use > When you want to use widgets from different sources yet want to use uniform programming model

jmaki Demo Create jmaki apps in Netbeans

AJAX Toolkits and Frameworks

Types of AJAX Toolkit and Framework Solutions of Today AJAX-enabled JSF components Clients-side JavaScript Libraries Wrapper:jMaki Java to JavaScript/HTML translator:gwt Remoting via proxy

AJAX-enabled JSF Components AJAX-enabled JavaServer Faces components hides all the complexity of AJAX programming > Page author does not need to know JavaScript > The burden is shifted to component developers Leverages drag-and-drop Web application development model of Faces through an IDE > You can drag and drop AJAX-enabled Faces components within Sun Java Studio Creator 2 (and other Faces-aware IDE's) to build AJAX applications JavaServer Faces components are reusable > More AJAX-enabled Faces components are being built by the community

Implementations Blueprint AJAX-enabled JSF components (open-source) > http://developers.sun.com/ajax/componentscatalog.jsp > https://bpcatalog.dev.java.net/ajax/jsf-ajax/ ajax4jsf (open-source) > Can add AJAX capability to existing applications > https://ajax4jsf.dev.java.net/ ICEfaces (ICESoft) - commercial > http://www.icesoft.com/products/icefaces.html

Client Side JavaScript Libraries HTML Pages, JavaScript Event Handlers UI Widgets & Components Remoting Abstraction Layer XMLHttpRequest iframe JavaScript Utilities

Architectural Layers (Client-side) Remoting abstraction layer > Hides handling of XMLHttpRequest and IFrame Widgets and components > Provides ready-to-use UI widgets such as calendar, button, etc JavaScript event handlers > Provides client-side logic

Characteristics of Client Side JavaScript Libraries Server side technology agnostic > The server side technology can be Java EE,.Net, PHP, Ruby on Rails, etc. Should be accessible during runtime either locally or through a URL You can use various client-side libraries in a single application > Use widgets from multiple libraries

Client-side JavaScript Libraries DOJO Toolkit (open-source) > Key focus on user experience > Provides APIs for history manipulation and navigation control > Provides client-side for bookmarking and URL manipulation > Most prominent and comprehensive > Gaining a leadership in this space > Major industry support (Sun, IBM) > http://dojotoolkit.com/

Other client-side JavaScript Libraries Prototype > Focuses more on AJAX interactions > JavaScript objects and utility methods > Used by other toolkit libaries > http://prototype.conio.net/ Script.aculo.us > Built on Prototype > Nice set of visual effects and controls > http://script.aculo.us/ Rico > Built on Prototype > Rich AJAX components and effects > http://openrico.org/ DHTML Goodies > Various DHTML and AJAX scripts > http://www.dhtmlgoodies.com/

What is Google Web Toolkit? Open source Java software development framework that makes writing AJAX applications easy > Java-to-JavaScript compiler and a special web browser that helps you debug your GWT applications You can develop and debug AJAX applications in the Java language using the Java development tools of your choice When you deploy your application to production, the compiler translates your Java application to browsercompliant JavaScript and HTML

GWT User Interface Classes Similar to those in existing UI frameworks such as Swing and SWT except that the widgets are rendered using dynamicallycreated HTML rather than pixel-oriented graphics While it is possible to manipulate the browser's DOM directly using the DOM interface, it is far easier to use classes from the Widget hierarchy Using widgets makes it much easier to quickly build interfaces that will work correctly on all browsers

GWT Widget Gallery

Remoting via Proxy (Client & Server) HTML Pages, JavaScript Event Handlers Java Classes Proxy Skeleton XMLHttpRequest Remote Abstraction Layer iframe HTTP Get/Post Framework runtime

Characteristics of Remoting via Proxy Framework Similar to general RPC communication schemes Allows RMI like syntax in the client side JavaScript code Framework generates client stub (Proxy), which is a JavaScript code Framework provides server side runtime Client stub (Proxy) handles marshaling of parameters and return value

Remoting via Proxy Implementations Direct Web Remoting (DWR) > Designed specifically for Java application at the back end > Do RPC calls from client-side JavaScript to Java objects in a web container server side > http://getahead.ltd.uk/dwr JSON-RPC > Lightweight remote procedure call protocol similar to XML-RPC > http://json-rpc.org/ > There are language-specific implementations > JSON-RPC-Java > http://oss.metaparadigm.com/jsonrpc/

Summary & Resources So... What Should I Use?

Summary AJAX helps make applications more interactive J2EE technology is a great platform for AJAX applications AJAX does not come for free Start small and don t overdo it Choose the right Toolkits and Frameworks for your application

So What Should I Use? Assuming You are using Java EE... On the UI side > Use AJAX-enabled JavaServer Faces components whenever possible using an Faces-enabled IDE such as Sun Java Studio Creator 2 > If you are not ready to commit yourself to Faces component solutions yet, use jmaki > If you want to have total control on the client side JavaScript coding, use Dojo toolkit > If you already have Swing apps that you want to expose as AJAX-fied Web apps or if you do not want to deal with JavaScript coding, use GWT

So What Should I Use? Assuming You are using Java EE... On the business logic side > If you already have Java EE business logic that you want to be exposed as RMI calls on the client with AJAX behavior, use DWR > If you are already using a particular Web application framework for building majority of your web application and the framework has AJAX extension, use it

For More Information The BluePrints Solutions catalog on AJAX: > https://bpcatalog.dev.java.net/nonav/solutions.html AJAX Q & A > https://blueprints.dev.java.net/ajax-faq.html Asynchronous JavaScript Technology and XML (AJAX) With Java 2 Platform, Enterprise Edition > http://java.sun.com/developer/technicalarticles/j2ee/ajax/index.html AJAX Frameworks > http://ajaxpatterns.org/wiki/index.php?title=ajaxframeworks AJAX Library and Frameworks Comparison > http://wiki.osafoundation.org/bin/view/projects/ajaxlibraries AJAX Developer Resource Center > http://developers.sun.com/ajax/ JavaScript Developer Site > java.sun.com/javascript

Cross Browser Resources Cross Browser Discussion > http://www.quirksmode.org/index.html > http://www.ajaxian.com/archives/browsers/index.html Cross Browser quirk > http://www.quirksmode.org/blog/archives/2005/09/xmlhttp_notes_r_2.html JavaScript libraries such as Dojo that makes these differences less painful > http://dojotoolkit.org/

AJAX and jmaki for Web 2.0 Development using Java Inyoung Cho Java Technology Evangelist Sun Microsystems, Inc.