Chapter 11. Using JSNI—JavaScript Native Interface

 

This chapter covers

  • Defining JSNI, including when and how to use it
  • Creating JavaScript overlays and quick JSONP handling
  • Wrapping JavaScript libraries and using them in GWT
  • Exposing your application as an API

Until now we’ve been looking at the various enhancements and help that GWT brings to web application development. We’ve covered widgets, panels, handling events, creating your own widgets and applications, and communicating with the server. Along the way we’ve been using the great tool support that comes with Java, and consequently GWT, such as integrated development environments, code completion, syntax and semantic checking, and debugging.

Whether you knew it or not, GWT has been protecting you from problems typically associated with web application development: issues such as managing browser differences in implementation and securing against the introduction of memory leaks (a typical problem around event handling).

Most everything you could want to do in an application is possible using standard GWT. In this chapter we’ll look at what happens when you step away from the protection of GWT and start hammering the metal yourself with JavaScript. Let’s look at a few reasons why you might want to do this:

11.1. What is JSNI?

11.2. Should you use JavaScript Native Interface?

11.3. Benefiting from the Google Plugin for Eclipse

11.4. Interacting with the browser

11.5. Handling objects from JavaScript

11.6. Wrapping a third-party library

11.7. Exposing an API to JavaScript

11.8. Summary