Chapter 6. Integrating Legacy and Third-Party Ajax Libraries

 

This chapter covers

  • Working with the JavaScript Native Interface
  • Creating JSNI Wrappers
  • Dealing with JavaScript eventing models
  • Working with the JSIO project

Before software can be reusable it first has to be usable.

Ralph Johnson

Although we believe GWT represents a superior environment for developing Ajax applications, sometimes the functionality you want to reuse is in existing JavaScript libraries. These might be your own legacy code or third-party libraries. Additionally, there may be times when you want to directly tweak aspects of your GWT application with JavaScript. To perform either of these tasks, you need to use JSNI.

We introduced JSNI in chapter 1 and used it in several other examples in this book, so you should already have a handle on the basics. Though JSNI is very powerful, it can also be confusing and problematic. When working with JSNI, you have to keep in mind that you’re on your own, and your own feet are in range of your shotgun. Methods that you implement as native JavaScript, or that you wrap and inherit, are typically less portable across different browsers, are more prone to memory leaks, and are less performant than JavaScript optimized and emitted by the GWT compiler. For this reason, though it’s possible to use JSNI for more than integration, we recommend that you stick to integrating existing well-tested JavaScript code when using JSNI. That will be our focus here.

6.1. A closer look at JSNI

6.2. Wrapping JavaScript libraries

6.3. Managing GWT-JavaScript interaction

6.4. Wrapping JavaScript with GWT-API-Interop

6.5. Summary