Google Web Toolkit (GWT) is an open source Java development framework for building Ajax-enabled web applications. Instead of the hodgepodge of technologies that developers typically use for Ajax-javascript, HTML, CSS, and XMLHttpRequest-GWT lets developers implement rich client applications with pure Java, using familiar idioms from the AWT, Swing, and SWT. GWT goes beyond most Ajax frameworks by making it easy to build desktop-like applications that run in the ubiquitous browser, where the richness of the user interface is limited only by the developers imagination. This book focuses on the more advanced aspects of GWT that you need to implement real-world applications with rich user interfaces but without the heavy lifting of javascript and other Ajax-related technologies. Each solution in this practical, hands-on book is more than a recipe. The sample programs are carefully explained in detail to help you quickly master advanced GWT techniques, such as implementing drag-and-drop, integrating javascript libraries, and using advanced event handling methodologies. Solutions covered include * Building custom GWT widgets, including both high-level composites and low-level components * Implementing a viewport class that includes iPhone-style automated scrolling * Integrating web services with GWT applications * Incorporating the Script.aculo.us javascript framework into GWT applications * Combining Hibernate and GWT to implement database-backed web applications * Extending the GWT PopupPanel class to implement a draggable and resizable window * Creating a drag-and-drop module, complete with drag sources and drop targets * Deploying GWT applications to an external server * Dynamically resizing flex tables * Using GWT widgets in legacy applications developed with other frameworks, such as Struts and JavaServer Faces Complete Sample Code Available at www.coolandusefulgwt.com All of the code used in this book has been tested, both in hosted and web modes, and in an external version of Tomcat (version 5.5.17), under Windows, Linux, and Mac OS X. For Windows and Linux, we used 1.4.60, and for the Mac we used 1.4.61. NOTE: There are three separate versions of the code. Please download the correct JAR file for the operating system you are using. Foreword xiii Preface xvi Acknowledgments xviii About the Authors xix Solution 1: GWT Fundamentals and Beyond 1 Solution 2: javascript Integration 53 Solution 3: Custom Widget Implementation 71 Solution 4: Viewports and Maps 103 Solution 5: Access to Online Web Services 133 Solution 6: Drag and Drop 167 Solution 7: Simple Windows 199 Solution 8: Flex Tables 237 Solution 9: File Uploads 283 Solution 10: Hibernate Integration 303 Solution 11: Deployment to an External Server 325 Solution 12: GWT and Legacy Code 343 Index 371
Author(s): David Geary, Rob Gordon
Edition: 1
Publisher: Prentice Hall
Year: 2007
Language: English
Pages: 408
Google Web toolkit solutions......Page 1
Contents......Page 8
Foreword......Page 14
Preface......Page 17
Acknowledgments......Page 19
About the Authors......Page 20
In This Book......Page 22
Stuff You’re Going to Learn......Page 24
Introduction to GWT Widgets......Page 25
Anatomy of a GWT Application......Page 28
User Interfaces Composed with GWT Panels......Page 29
The Root Panel......Page 31
The user.client.ui API......Page 32
Widget Styling with CSS Styles......Page 33
Event-Driven Programming with GWT......Page 35
Internationalization and Localization......Page 39
Implementing the Four Steps for GWT Internationalization......Page 40
Using GWT’s i18nCreator Command......Page 43
A New “View” in Your GWT Web Application......Page 44
GWT’s History Mechanism......Page 47
Adding the History Class and History Listeners......Page 48
Handling the Browser’s Back Button......Page 51
Use of Deferred Commands to Give Widgets Keyboard Focus......Page 53
Remote Procedure Call Implementation......Page 55
Custom Widget Use......Page 61
Custom Widget Packaging in GWT Modules......Page 64
The Complete Login Application......Page 68
Stuff We Covered in This Solution......Page 73
Stuff You’re Going to Learn......Page 74
The Script.aculo.us JavaScript Library Integration......Page 75
Importing a JavaScript File in Your HTML File......Page 82
Importing a JavaScript File in Your GWT Configuration File......Page 84
A JavaScript Calendar Integration......Page 85
Stuff We Covered in This Solution......Page 90
Stuff You’re Going to Learn......Page 92
Composite Custom Widgets......Page 93
Composite Widgets and Pass-Through Methods......Page 109
The Text Box’s Keyboard Listener......Page 110
Implementing the HasText and HasName Interfaces......Page 111
Incorporating the Script.aculo.us Blind Down Effect......Page 112
A Low-Level Custom Widget......Page 116
Parameterizing Script.aculo.us Effects in a Custom Widget......Page 120
Stuff We Covered in This Solution......Page 121
Stuff You’re Going to Learn......Page 124
Viewports......Page 125
A General-Purpose Viewport Widget......Page 126
The Map Application’s Files and Directories......Page 127
The Viewport Implementation......Page 128
Using a Focus Panel to React to Mouse Events......Page 131
Clipping the Viewport’s View......Page 132
Adding a Default CSS Style Name for a Custom Widget......Page 133
The Viewport’s Use of a Focus Panel: Revisited......Page 136
A Viewport’s View with Animated Gestures......Page 138
The Final Version of the Viewport......Page 141
Animating Scrolling in the Same Direction as the Drag Gesture......Page 150
Varying the Speed of the Scrolling Animation......Page 151
Stuff We Covered in This Solution......Page 152
Stuff You’re Going to Learn......Page 154
Exploring the Example Application......Page 155
Summarizing the Map Application’s Files and Directories......Page 159
Implementing the YahooMaps Application......Page 160
Access to Yahoo!’s Web Service......Page 167
Zoom!......Page 172
Stuff We Covered in This Solution......Page 185
Stuff You’re Going to Learn......Page 188
The Drag-and-Drop Example Application......Page 189
The Drag-and-Drop Module......Page 191
Inheriting the Drag-and-Drop Module in an Application’s Configuration File......Page 193
Implementation of the Drag-and-Drop Application......Page 194
Using the Music Player and Shopping Cart Panel Components......Page 195
Using Drag Sources and Drop Targets......Page 197
Defining the CSS Classes......Page 202
Drag and Drop Implementation in a GWT Module......Page 203
The Abstract Drag Source and Drop Target Classes......Page 204
Mouse Listeners......Page 209
Stuff We Covered in This Solution......Page 218
Solution 7 Simple Windows......Page 220
Stuff You’re Going to Learn......Page 221
A Window Built from a Flex Table......Page 224
The Simple Window......Page 225
Using Pop-Up Panels......Page 231
Overriding a Pop-Up Panel’s Default Event Handling Behavior......Page 232
Using a GWT Flex Table and Formatting Its Cells......Page 235
Sinking Events......Page 236
Manipulating the Z Index for a Widget’s DOM Element......Page 238
Resizing Pop-Up Panels......Page 240
Preventing Unwanted Browser Effects......Page 243
The Window Bar......Page 246
Aligning Widgets Within Cells in a Horizontal Panel......Page 249
Simulating a 3-D Button with a Mouse Listener and Images......Page 250
Moving Pop-Up Panels......Page 251
Preventing Unwanted Browser Effects in the Window Bar......Page 255
Stuff We Covered in This Solution......Page 257
Stuff You’re Going to Learn......Page 258
Introduction to Flex Tables......Page 259
An Easy Flex Table......Page 267
Row Deletion in a Flex Table......Page 272
Flex Table Cell Editing......Page 274
Dynamic Resizing of a Flex Table’s Columns......Page 278
Constructing Event Listeners and Firing Events with GWT......Page 280
Building the ResizableCellPanel Widget......Page 285
Incorporating the ResizableCellPanel into a Flex Table......Page 290
Data Page-Through in a Flex Table......Page 293
Using the Pager Widget......Page 300
Stuff We Covered in This Solution......Page 303
Stuff You’re Going to Learn......Page 304
GWT’s File Upload Widget......Page 305
Creating the User Interface......Page 311
Parsing JavaScript Object Notation (JSON)......Page 312
Apache Commons fileUpload......Page 318
Stuff We Covered in This Solution......Page 323
Stuff You’re Going to Learn......Page 324
The Hibernate Example Application......Page 325
The Hibernate Configuration File......Page 337
The POJO Java Class......Page 338
The Contact Mapping File......Page 340
RPC Servlet Implementation......Page 341
Eclipse Configuration......Page 344
Stuff We Covered in This Solution......Page 345
Stuff You’re Going to Learn......Page 346
External Server Directory Structure......Page 347
Use of Ant to Automate the Build Process......Page 351
Development Versus Deployment......Page 360
Debugging Deployed Applications......Page 361
Stuff We Covered in This Solution......Page 363
Stuff You’re Going to Learn......Page 364
A Real-World Struts/GWT Hybrid Application......Page 365
A Simple Struts Application......Page 366
JSP Pages......Page 369
The Backing Bean, the Form Bean, and the Action Bean......Page 372
GWT/Struts Hybrid Application......Page 374
Hybrid Application’s Files and Directories......Page 376
Ant Build File, Modified to Incorporate Struts......Page 377
Hybrid Application’s Code......Page 378
Use of JSON to Configure a GWT Widget......Page 382
Legacy Code and GWT Widget Coordination......Page 388
Replacement of HTML and JSP Views with GWT Views......Page 389
Deeper Framework Integration......Page 390
Stuff We Covered in This Solution......Page 391
A......Page 392
C......Page 393
D......Page 395
E......Page 396
F......Page 397
H......Page 398
J......Page 399
L......Page 400
M......Page 401
N–O......Page 403
Q–R......Page 404
S......Page 405
T......Page 406
W......Page 407
X–Z......Page 408