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



Similar documents
WA 2. GWT Martin Klíma

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

Rich User Interfaces for Web-Based Corporate Applications

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

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 :

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

Introduction to web development and JavaScript

Preface. Motivation for this Book

Fast track to HTML & CSS 101 (Web Design)

The Google Web Toolkit (GWT): Declarative Layout with UiBinder Basics

Rich-Internet Anwendungen auf Basis von ColdFusion und Ajax

GUI and Web Programming

Performance Testing for Ajax Applications

From Desktop to Browser Platform: Office Application Suite with Ajax

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

Chapter 1. Introduction to web development

Web. Programming. Hans- Pe0er Halvorsen, M.Sc. h0p://home.hit.no/~hansha/?page=sojware_development

Rich Internet Applications

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

Mobile Web Design with HTML5, CSS3, JavaScript and JQuery Mobile Training BSP-2256 Length: 5 days Price: $ 2,895.00

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

WEB DEVELOPMENT IA & IB (893 & 894)

Client-side Web Engineering From HTML to AJAX

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

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

Chapter 1 Introduction to web development and PHP

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

Web Applications Testing

10CS73:Web Programming

Enterprise Application Development In Java with AJAX and ORM

Web Application Development

How To Write An Ria Application

INTERNET PROGRAMMING AND DEVELOPMENT AEC LEA.BN Course Descriptions & Outcome Competency

Chapter 12: Advanced topic Web 2.0

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

Entrance exam for PBA in Web Development

Web-JISIS Reference Manual

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Developer Tutorial Version 1. 0 February 2015

Developing Web Views for VMware vcenter Orchestrator

OPENTABLE GROUP SEARCH MODULE GETTING STARTED ADD RESERVATIONS TO YOUR WEBSITE

Ready, Set, Go Getting started with Tuscany

Responsive Web Design Creative License

Data Visualization in Ext Js 3.4

Short notes on webpage programming languages

WIRIS quizzes web services Getting started with PHP and Java

ShoreTel Enterprise Contact Center 8 Installing and Implementing Chat

Web Development using PHP (WD_PHP) Duration 1.5 months

Introduction to Ingeniux Forms Builder. 90 minute Course CMSFB-V6 P

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

Designing and Implementing Support for Web Browser-Based UIs by Using Ajax Technology

Curl Building RIA Beyond AJAX

Google Web Toolkit GWT

Links Getting Started with Widgets, Gadgets and Mobile Apps

Whitepapers at Amikelive.com

XML Processing and Web Services. Chapter 17

Up and Running with LabVIEW Web Services

4 Understanding. Web Applications IN THIS CHAPTER. 4.1 Understand Web page development. 4.2 Understand Microsoft ASP.NET Web application development

Framework as a master tool in modern web development

WEB DESIGN COURSE CONTENT

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

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

Honoring a Tradition of Simplicity. The Foundation. Getting Started

Building Ajax Applications with GT.M and EWD. Rob Tweed M/Gateway Developments Ltd

Google App Engine f r o r J av a a v a (G ( AE A / E J / )

CLASSROOM WEB DESIGNING COURSE

Interactive Data Visualization for the Web Scott Murray

IT3504: Web Development Techniques (Optional)

DIPLOMA IN WEBDEVELOPMENT

DreamFactory & Modus Create Case Study

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

2011 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media,

Operational Decision Manager Worklight Integration

JavaFX Session Agenda

How To Write A Web Server In Javascript

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

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

Server-Side Scripting and Web Development. By Susan L. Miertschin

IT3503 Web Development Techniques (Optional)

CST 150 Web Design I CSS Review - In-Class Lab

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

Example. Represent this as XML

Abstract. Description

Web Development CSE2WD Final Examination June (a) Which organisation is primarily responsible for HTML, CSS and DOM standards?

Web Authoring CSS. Module Descriptor

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

Adding Panoramas to Google Maps Using Ajax

Introduction to BlackBerry Smartphone Web Development Widgets

Web Design Technology

Advantage of Jquery: T his file is downloaded from

Web Cloud Architecture

We automatically generate the HTML for this as seen below. Provide the above components for the teaser.txt file.

Web Development with the Eclipse Platform

Create interactive web graphics out of your SAS or R datasets

Certified Selenium Professional VS-1083

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

Introduction to Web Development

An Introduction to the Development of Web Applications using Ruby on Rails with Ajax

Time Tracking System with GWT

CaptainCasa. CaptainCasa Enterprise Client. CaptainCasa Enterprise Client. Feature Overview

Transcription:

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

Introduction Ajax (Asynchronous JavaScript and XML) refers to a broad range of techniques Beyond the technical jargon, Ajax represents an architecture for the software that is designed to be used with any web browser, but that includes an interface with the responsive feel of a desktop application

Introduction For example, a grid component such as a spreadsheet that appears in the web page responds instantly to the user's manipulation of the data, without the time delays or visual disruptions caused by the page "refreshing" or being rebuilt with new HTTP requests. Google's Gmail and Calendar, and Yahoo! Maps, are three examples of typical Ajax applications

AJAX in a nutshell Ajax works by communicating with the application's middle and/or database tiers using a client-side JavaScript object. This object is called XMLHttpRequest (XHR) The web page is composed of and programmed with common, standard technologies namely, HTML/XHTML, cascading style sheets (CSS), JavaScript, and the Document Object Model API that lies behind each web page's structure

AJAX in a nutshell The data that the page exchanges with its server tiers, such as a product database, can be plain text, XML, or a format called JavaScript Object Notation (JSON) For example, the user might choose a product name from a selection list widget on a web page. In response to this event, the application uses XHR to send a request for data on this product

AJAX in a nutshell The page never changes, because the application sent the request asynchronously behind the scenes. The server component, such as a PHP file or a servlet, receives the HTTP request, then sends back a response containing information about the product, in, say, XML or JSON format. The application processes the request using JavaScript's DOM API, or by converting the JSON value to a client-side object. The user sees the new information on the web page, hopefully without a very long delay

How to program in AJAX? A developer will typically create his Ajax application by writing XHTML pages and JavaScript code with his favorite integrated development environment (IDE) or even text editors. A number of different libraries and frameworks exist (cf. http://en.wikipedia.org/wiki/ List_of_Ajax_frameworks for a list) Dojo toolkit Prototype Yahoo! User Interface library script.aculo.us. They are designed for developers who are already fairly well advanced in their JavaScript knowledge

GWT The GWT takes a different approach to Ajax Using the GWT framework, you can design and program your user interface using only the Java language. You can use the GWT's command-line tools to check the syntax of the Java classes, then automatically generate the JavaScript for the application's client-side The design of the user interface is very similar to using Java's Swing API

GWT You can thus view the GWT as a JavaScript-generation tool for Java programmers, as well as a framework for creating redistributable or extensible user-interface widgets You do not have to know a lick of JavaScript, although you can include raw JavaScript in your code using special programming constructs that the GWT provides

My First GWT application Reference: https://developers. google.com/webtoolkit/doc/latest/tut orial/gettingstarted

My First GWT application 1. Set-up the development environment (Eclipse if you like the GWT plugin) and/or command-line tools webappcreator creates all the needed files and directories needed for the application

My First GWT application 2. Create a new project directories /src/com/google/gwt/sample/stockwatcher - Contains the GWT module definition and initial application files /test/com/google/gwt/sample/stockwatcher - Contains JUnit test directory and a starter test class /war - Contains static resources that can be served publicly, such as image files, style sheets, and HTML host pages /war/web-inf - Contains Java web application files /war/web-inf/lib - Contains Java web application libraries

My First GWT application files StockWatcher.gwt.xml - GWT module definition StockWatcher.html - host page StockWatcher.css - application style sheet web.xml - Java web application descriptor The code for a web application executes within an HTML document. In GWT, we call this the host page. The host page references the application style sheet StockWatcher.java - GWT entry point class GreetingService.java, GreetingServiceAsync.java, GreetingServiceImpl.java GWT sample RPC classes gwt-servlet.jar - GWT server runtime library StockWatcherTest.java - Starter test case for StockWatcher The entry point class implements the GWT interface EntryPoint. It contains the method onmoduleload

My First GWT application 3. Code your application Selection of the needed widgets see https://developers.google.com/webtoolkit/doc/latest/refwidgetgallery In our example...

My First GWT application Choose the panel structure (analogously to Java Swing)

My First GWT application Define event handling

G:\Massimo\Didattica\2011_2012\ProgettoApplicazioniSoftware\Slides\8 Code_StockWatcher.html giovedì 12 aprile 2012 12:29 <!doctype html> <!-- The DOCTYPE declaration above will set the --> <!-- browser's rendering engine into --> <!-- "Standards Mode". Replacing this declaration --> <!-- with a "Quirks Mode" doctype is not supported. --> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link type="text/css" rel="stylesheet" href="stockwatcher.css"> <title>stockwatcher</title> <script type="text/javascript" language="javascript" src= "stockwatcher/stockwatcher.nocache.js"></script> </head> <body> <h1>stockwatcher</h1> <div id="stocklist"></div> <iframe src="javascript:''" id=" gwt_historyframe" tabindex='-1' style= "position:absolute;width:0;height:0;border:0"></iframe> <noscript> <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif"> Your web browser must have JavaScript enabled in order for this application to display correctly. </div> </noscript> </body> </html> -1-

G:\Massimo\Didattica\2011_2012\ProgettoApplicazioniSoftware\Slides\8 Code_StockPrice.java giovedì 12 aprile 2012 12:28 package com.google.gwt.sample.stockwatcher.client; public class StockPrice { private String symbol; private double price; private double change; public StockPrice() { public StockPrice(String symbol, double price, double change) { this.symbol = symbol; this.price = price; this.change = change; public String getsymbol() { return this.symbol; public double getprice() { return this.price; public double getchange() { return this.change; public double getchangepercent() { return 100.0 * this.change / this.price; public void setsymbol(string symbol) { this.symbol = symbol; public void setprice(double price) { this.price = price; public void setchange(double change) { this.change = change; -1-

G:\Massimo\Didattica\2011_2012\ProgettoApplicazioniSoftware\Slides\8 Code_StockWatcher.java giovedì 12 aprile 2012 12:29 package com.google.gwt.sample.stockwatcher.client; import com.google.gwt.core.client.entrypoint; import com.google.gwt.user.client.ui.button; import com.google.gwt.user.client.ui.flextable; import com.google.gwt.user.client.ui.horizontalpanel; import com.google.gwt.user.client.ui.label; import com.google.gwt.user.client.ui.rootpanel; import com.google.gwt.user.client.ui.textbox; import com.google.gwt.user.client.ui.verticalpanel; import com.google.gwt.event.dom.client.clickevent; import com.google.gwt.event.dom.client.clickhandler; import com.google.gwt.event.dom.client.keycodes; import com.google.gwt.event.dom.client.keypressevent; import com.google.gwt.event.dom.client.keypresshandler; import com.google.gwt.user.client.window; import java.util.arraylist; import com.google.gwt.user.client.timer; import com.google.gwt.user.client.random; import com.google.gwt.i18n.client.numberformat; import com.google.gwt.i18n.client.datetimeformat; import java.util.date; /** * Entry point classes define <code>onmoduleload()</code>. */ public class StockWatcher implements EntryPoint { private static final int REFRESH_INTERVAL = 5000; // ms private VerticalPanel mainpanel = new VerticalPanel(); private FlexTable stocksflextable = new FlexTable(); private HorizontalPanel addpanel = new HorizontalPanel(); private TextBox newsymboltextbox = new TextBox(); private Button addstockbutton = new Button("Add"); private Label lastupdatedlabel = new Label(); private ArrayList<String> stocks = new ArrayList<String>(); /** * Entry point method. */ public void onmoduleload() { // Create table for stock data. stocksflextable.settext(0, 0, "Symbol"); stocksflextable.settext(0, 1, "Price"); stocksflextable.settext(0, 2, "Change"); stocksflextable.settext(0, 3, "Remove"); // Assemble Add Stock panel. addpanel.add(newsymboltextbox); addpanel.add(addstockbutton); // Assemble Main panel. mainpanel.add(stocksflextable); mainpanel.add(addpanel); mainpanel.add(lastupdatedlabel); -1-

G:\Massimo\Didattica\2011_2012\ProgettoApplicazioniSoftware\Slides\8 Code_StockWatcher.java giovedì 12 aprile 2012 12:29 // Associate the Main panel with the HTML host page. RootPanel.get("stockList").add(mainPanel); // Move cursor focus to the input box. newsymboltextbox.setfocus(true); // Setup timer to refresh list automatically. Timer refreshtimer = new Timer() { @Override public void run() { refreshwatchlist(); ; refreshtimer.schedulerepeating(refresh_interval); // Listen for mouse events on the Add button. addstockbutton.addclickhandler(new ClickHandler() { public void onclick(clickevent event) { addstock(); ); // Listen for keyboard events in the input box. newsymboltextbox.addkeypresshandler(new KeyPressHandler() { public void onkeypress(keypressevent event) { if (event.getcharcode() == KeyCodes.KEY_ENTER) { addstock(); ); private void addstock() { final String symbol = newsymboltextbox.gettext().touppercase().trim(); newsymboltextbox.setfocus(true); // Stock code must be between 1 and 10 chars that are numbers, letters, // or dots. if (!symbol.matches("^[0-9a-z\\.]{1,10$")) { Window.alert("'" + symbol + "' is not a valid symbol."); newsymboltextbox.selectall(); return; newsymboltextbox.settext(""); // Don't add the stock if it's already in the table. if (stocks.contains(symbol)) return; // Add the stock to the table. int row = stocksflextable.getrowcount(); stocks.add(symbol); stocksflextable.settext(row, 0, symbol); // Add a button to remove this stock from the table. -2-

G:\Massimo\Didattica\2011_2012\ProgettoApplicazioniSoftware\Slides\8 Code_StockWatcher.java giovedì 12 aprile 2012 12:29 Button removestockbutton = new Button("x"); removestockbutton.addclickhandler(new ClickHandler() { public void onclick(clickevent event) { int removedindex = stocks.indexof(symbol); stocks.remove(removedindex); stocksflextable.removerow(removedindex + 1); ); stocksflextable.setwidget(row, 3, removestockbutton); // Get the stock price. refreshwatchlist(); /** * Generate random stock prices. */ private void refreshwatchlist() { final double MAX_PRICE = 100.0; // $100.00 final double MAX_PRICE_CHANGE = 0.02; // +/- 2% StockPrice[] prices = new StockPrice[stocks.size()]; for (int i = 0; i < stocks.size(); i++) { double price = Random.nextDouble() * MAX_PRICE; double change = price * MAX_PRICE_CHANGE * (Random.nextDouble() * 2.0-1.0); prices[i] = new StockPrice(stocks.get(i), price, change); updatetable(prices); /** * Update the Price and Change fields all the rows in the stock table. * * @param prices * Stock data for all rows. */ private void updatetable(stockprice[] prices) { for (int i = 0; i < prices.length; i++) { updatetable(prices[i]); // Display timestamp showing last refresh. lastupdatedlabel.settext("last update : " + DateTimeFormat.getMediumDateTimeFormat().format(new Date())); /** * Update a single row in the stock table. * * @param price * Stock data for a single row. */ -3-

G:\Massimo\Didattica\2011_2012\ProgettoApplicazioniSoftware\Slides\8 Code_StockWatcher.java giovedì 12 aprile 2012 12:29 private void updatetable(stockprice price) { // Make sure the stock is still in the stock table. if (!stocks.contains(price.getsymbol())) { return; int row = stocks.indexof(price.getsymbol()) + 1; // Format the data in the Price and Change fields. String pricetext = NumberFormat.getFormat("#,##0.00").format( price.getprice()); NumberFormat changeformat = NumberFormat.getFormat("+#,##0.00;-#,##0.00"); String changetext = changeformat.format(price.getchange()); String changepercenttext = changeformat.format(price.getchangepercent()); // Populate the Price and Change fields with new data. stocksflextable.settext(row, 1, pricetext); stocksflextable.settext(row, 2, changetext + " (" + changepercenttext + "%)"); -4-