GWT in Action: Easy Ajax with the Google Web Toolkit

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The Google Web Toolkit is a new technology that automatically translates Java into JavaScript, making Ajax applications easier to code and deploy. GWT in Action is a comprehensive tutorial for Java developers interested in building the next generation of rich, web-based applications. This book was written by Robert Hanson, creator of the popular GWT Widget Library and Adam Tacy a major contributor to the GWT Widget Library. There is a new emphasis on building rich, web-based applications. These applications can be difficult to build because they rely on JavaScript, which lacks the sophisticated object-oriented structures and static typing of Java, they are tricky to debug, and they require you to manage numerous browser inconsistencies. In May of 2006 Google released the Google Web Toolkit (GWT). GWT enables developers to create Ajax applications in Java. With GWT, you can build your applications using a real object-oriented language and take advantage of Java tools like Eclipse that are already available. Instead of trying to bring tool support to Ajax, Google brought Ajax to a place where the tools already existed. GWT in Action shows you how to take advantage of these exciting new tools. Readers will follow an example running throughout the book and quickly master the basics of GWT: widgets, panels, and event handling. The book covers the full development cycle, from setting up your development environment, to building the application, then deploying it to the web server. The entire core GWT library is discussed, with details and examples on how it can be extended. Purchase of the print book comes with an offer of a free PDF eBook from Manning. Also available is all code from the book.

Author(s): Robert Hanson, Adam Tac
Publisher: Manning Publications
Year: 2007

Language: English
Pages: 631
Tags: Библиотека;Компьютерная литература;Java;

GWT in Action......Page 1
brief contents......Page 8
contents......Page 10
preface......Page 20
acknowledgments......Page 22
about this book......Page 24
about the title......Page 31
about the cover illustration......Page 32
Getting started......Page 34
Introducing GWT......Page 36
1.1 A walk through GWT......Page 38
1.1.1 Explaining GWT's Java-to-JavaScript compiler......Page 39
1.1.2 Using JSNI to execute JavaScript from Java......Page 41
1.1.3 Accessing the JRE emulation library......Page 43
1.1.4 Understanding GWT's widget and panel library......Page 45
1.1.5 Examining GWT’s internationalization and configuration tools......Page 47
1.1.6 Calling remote procedures with GWT......Page 49
1.1.7 Investigating GWT’s XML parser......Page 53
1.1.8 Managing the browser history......Page 54
1.1.9 Introducing GWT’s JUnit integration......Page 55
1.2 GWT vs. other solutions......Page 56
1.2.1 GWT vs. Swing......Page 58
1.2.2 GWT vs. Echo2......Page 59
1.2.3 GWT vs. JavaServer Faces......Page 60
1.2.4 GWT vs. Ruby on Rails......Page 62
1.3.1 Building and running an example application......Page 63
1.3.2 Building Tic-Tac-Toe with GWT......Page 65
1.4 Summary......Page 70
Creating the default application......Page 71
2.1 The GWT application development lifecycle......Page 72
2.2 Stage 1: Creating a GWT application......Page 77
2.2.1 Creating the project......Page 80
2.2.2 Creating an application......Page 83
2.2.3 Setting up internationalization......Page 87
2.2.4 Implementing internationalization......Page 89
2.2.5 Creating unit test cases......Page 90
2.2.6 Importing into your IDE......Page 92
2.3 Summary......Page 96
Advancing to your own application......Page 97
3.1 Describing the application example......Page 98
3.2 Stage 2: Developing your application......Page 100
3.2.1 Implementing internationalization......Page 101
3.2.2 Constructing the application......Page 105
3.2.3 Applying styling......Page 116
3.3.1 Preparing for hosted mode......Page 119
3.3.2 Running the Dashboard in hosted mode......Page 123
3.3.3 Debugging the Dashboard in hosted mode through Eclipse......Page 125
3.4 Stage 4: Compiling the code......Page 127
3.4.1 Compiling the code/preparing for web mode......Page 128
3.4.2 Viewing the compilation results......Page 130
3.5.1 Deploying to a web server......Page 131
3.6 Stage 6: Running in web mode......Page 132
3.7.1 Logging information on the client-side......Page 133
3.7.2 Logging information on the server-side......Page 136
3.8 Summary......Page 137
Building user interfaces......Page 140
Working with widgets......Page 142
4.1 What is a widget?......Page 144
4.1.1 Using widgets as Java objects......Page 145
4.1.2 Considering widgets as DOM elements......Page 146
4.2 The standard GWT widgets......Page 148
4.2.1 Interacting with the basic widgets......Page 151
4.2.2 Displaying text on the application......Page 164
4.2.3 Grabbing the user’s interaction using focus widgets......Page 166
4.2.4 Getting user input through text input......Page 172
4.3 Creating new widgets......Page 174
4.3.1 Creating new widgets by manipulating the DOM......Page 175
4.3.2 Creating new widgets by extending existing widgets......Page 179
4.4 Developing the Dashboard’s ToggleMenuItem widget......Page 183
4.4.1 Building the TwoComponentMenuItem......Page 184
4.4.2 Building the ToggleMenuItem......Page 187
4.5 Summary......Page 188
Working with panels......Page 190
5.1 What is a panel?......Page 191
5.1.1 Using panels as Java Objects......Page 192
5.1.2 Considering panels as DOM elements......Page 193
5.2 The standard GWT panels......Page 195
5.2.1 Interacting with simple panels......Page 197
5.2.2 Considering more complex panels......Page 203
5.2.3 Considering HTML table-based panels......Page 211
5.2.4 Considering composite panels......Page 214
5.3 Creating new panels......Page 215
5.3.1 Creating a new panel from scratch......Page 216
5.3.2 Creating a new panel by extending an existing panel......Page 219
5.4 Creating the Dashboard panel......Page 220
5.5 Summary......Page 224
Handling events......Page 225
6.1 Exploring events......Page 226
6.1.1 Identifying event model browser differences......Page 228
6.1.2 Understanding the GWT event model......Page 229
6.2.1 Sinking events......Page 233
6.2.2 Managing sunk events with the onBrowserEvent() method......Page 236
6.2.3 Linking sunk events to the onBrowserEvent() method......Page 240
6.2.4 Previewing events......Page 241
6.2.5 Handling events by extending the listener classes......Page 244
6.2.6 Moving events further into your GWT code......Page 245
6.3 Handling standard browser events......Page 249
6.3.1 Reacting to change......Page 251
6.3.2 Clicking around......Page 254
6.3.3 Gaining/Losing focus......Page 255
6.3.5 Loading images......Page 256
6.3.7 Scrolling......Page 257
6.3.8 Window resize events......Page 259
6.3.9 Window close events......Page 260
6.4.2 Reacting to closing pop-ups......Page 264
6.4.3 Tab events......Page 265
6.4.4 Tabling events......Page 267
6.4.5 Tree events......Page 268
6.5.1 Implementing the drag part......Page 269
6.5.2 Implementing the drop part......Page 274
6.6 Summary......Page 277
Creating composite widgets......Page 279
7.1 What is a composite widget?......Page 280
7.2 Composite widget development steps......Page 281
7.3 Building the editable label......Page 283
7.3.1 Step 1: Identifying the components......Page 284
7.3.2 Step 2: Choosing the panel layout and structure......Page 286
7.3.3 Step 3: Implementing the right GWT Java interfaces......Page 288
7.3.4 Step 4: Building the composite widget......Page 291
7.3.5 Step 5: Styling the composite widget......Page 300
7.4 Creating a composite widget from other composite widgets......Page 302
7.4.1 Creating a slider......Page 303
7.4.2 Constructing the ColourPicker composite......Page 306
7.5 Creating the Dashboard composite......Page 307
7.6 Summary......Page 309
Building JSNI components......Page 310
8.1 Introducing JavaScript Native Interface (JSNI)......Page 312
8.1.1 Understanding JSNI......Page 314
8.2 Communicating using JSNI......Page 323
8.2.1 Chatting to the browser via GWT Java......Page 324
8.2.2 Chatting to the browser via JavaScript......Page 325
8.2.3 Talking to a GWT application via a JavaScript API......Page 327
8.2.4 Talking between GWT applications......Page 329
8.3.2 Using the module XML to load a JavaScript library......Page 332
8.4 Wrapping a simple JavaScript library......Page 333
8.4.1 Accessing the loaded JavaScript library......Page 335
8.4.2 Using the widget in an application......Page 341
8.5.1 Generating the classes......Page 342
8.5.2 Keeping JavaScript objects as Java objects......Page 343
8.5.3 Calling user-defined code from a library......Page 345
8.5.4 Using a complex wrapped widget in an application......Page 347
8.6 Summary......Page 348
Modularizing an application......Page 350
9.1 Creating a modularization structure......Page 351
9.1.1 Modularization in GWT......Page 352
9.1.2 Including other modules in an application......Page 354
9.1.3 Setting source and other resource paths......Page 358
9.1.4 Defining an application’s server resources......Page 359
9.1.5 Managing an application’s GWT properties......Page 360
9.1.6 Replacing classes based on property values......Page 365
9.1.7 Registering generators in the XML module file......Page 366
9.1.8 Injecting resources into an application at runtime......Page 367
9.1.10 The Dashboard’s module XML file......Page 370
9.2 Including third-party modules......Page 372
9.3 Packaging your own modules......Page 374
9.4 Creating the Java package structure......Page 376
9.5 Summary......Page 377
Advanced techniques......Page 378
Communicating with GWT-RPC......Page 380
10.1 Underlying RPC concepts......Page 381
10.1.1 Understanding asynchronous communication......Page 383
10.1.2 Restrictions for communicating with remote servers......Page 384
10.1.3 Creating the Server Status project......Page 386
10.2.1 Understanding serializable data objects......Page 389
10.2.2 Defining the GWT-RPC service......Page 393
10.2.3 Preparing the client side of a GWT-RPC call......Page 399
10.2.4 Calling the remote server service......Page 401
10.3.1 Project overview......Page 403
10.3.2 Server-side service implementation......Page 404
10.3.3 Calling the service from the client......Page 405
10.4 Summary......Page 407
Examining client-side RPC architecture......Page 408
11.1.1 Encapsulating the Server Status component......Page 409
11.1.2 Encapsulating remote calls in a façade......Page 415
11.1.3 Callback routine using the Command pattern......Page 417
11.2.1 Understanding polling issues......Page 425
11.2.2 Implementing a continuously updating component......Page 426
11.2.3 Emulating server-push by blocking server threads......Page 431
11.3 Writing custom field serializers......Page 435
11.3.1 Creating a custom field serializer class......Page 436
11.3.2 Implementing custom field serialization......Page 437
11.4 Summary......Page 440
Classic Ajax and HTML forms......Page 442
12.1 Classic Ajax with RequestBuilder......Page 443
12.1.1 Examining HTTP methods......Page 444
12.1.2 Simple RPC with RequestBuilder......Page 447
12.1.3 Using RequestBuilder to load XML data......Page 450
12.2 Examining FormPanel basics......Page 457
12.2.1 Introducing the FormPanel......Page 458
12.2.2 Listening to FormPanel events......Page 461
12.2.3 Altering the FormPanel target......Page 462
12.2.4 Using the various form controls......Page 465
12.3 Summary......Page 472
Achieving interoperability with JSON......Page 475
13.1.1 Understanding the JSON data format......Page 476
13.2.1 Introducing the JSONValue object......Page 478
13.2.2 Examining basic JSON types......Page 479
13.2.3 Storing JSONValue objects in a JSONArray......Page 481
13.2.4 Collecting JSONValue objects in a JSONObject......Page 482
13.3 Creating a search component using JSON......Page 483
13.3.1 Examining the Yahoo Search API......Page 484
13.3.2 Implementing the Yahoo search component......Page 486
13.3.3 Sending JSON data to the server......Page 488
13.3.4 Parsing and validating a JSON server response......Page 490
13.4.1 Using JSON with Java on the server......Page 494
13.4.2 Using JSON with Perl on the server......Page 498
13.4.3 Using JSON with Ruby on the server......Page 500
13.5 Summary......Page 502
Automatically generating new code......Page 504
14.1 Generating new types......Page 505
14.2 Investigating GWT generators......Page 506
14.2.1 Basic generator code......Page 509
14.3 Creating a generator for the Dashboard......Page 510
14.3.1 Accessing the input class......Page 511
14.3.2 Accessing properties of the context......Page 512
14.3.3 Adding logging to a generator......Page 513
14.3.4 Generating the new type structure......Page 515
14.3.5 Creating the new class......Page 517
14.3.6 Using the classes that have been generated......Page 524
14.4 Summary......Page 525
Changing applications based on GWT properties......Page 527
15.1 Quick summary of properties......Page 528
15.2 Managing browser differences......Page 529
15.2.1 How GWT manages browser differences......Page 530
15.2.2 Building the Flash widget......Page 531
15.2.3 Setting up the property replacement......Page 534
15.3 Supporting internationalization in full......Page 535
15.3.1 Using static-string internationalization......Page 536
15.3.2 Using dynamic string internationalization......Page 549
15.4.1 Implementing the default component......Page 551
15.4.2 Locale-specific classes......Page 552
15.5 Implementing user-defined properties......Page 553
15.5.2 Defining a user-specified property provider......Page 554
15.5.4 Building the code......Page 555
15.6 Summary......Page 556
Completing the understanding......Page 558
Testing and deploying GWT applications......Page 560
16.1 Testing GWT code using JUnit......Page 561
16.1.1 Overview of JUnit for GWT developers......Page 562
16.1.2 Creating a new test case......Page 567
16.1.3 Testing asynchronous code......Page 570
16.2 Deploying GWT applications......Page 572
16.2.1 Organizing your project......Page 573
16.2.2 Installing RPC servlets......Page 581
16.3 Summary......Page 587
Peeking into how GWT works......Page 588
17.1.1 Investigating compilation......Page 589
17.1.2 Examining the output......Page 592
17.2 The GWT application-loading mechanism......Page 597
17.2.1 Legacy applications......Page 598
17.2.2 Standard applications......Page 599
17.2.3 Bootstrapping the standard application......Page 600
17.2.4 Cross-script applications......Page 605
17.3.1 Exploring the produced JavaScript......Page 606
17.3.2 Reviewing standard Java objects: the vector object......Page 607
17.3.3 Exploring program code as JavaScript......Page 609
17.3.4 Understanding the initialization code segment......Page 611
17.4 Summary......Page 612
index......Page 614