O'Reilly logo

Ajax on Java by Steven Douglas Olson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Ajax to Struts with DWR

There is really nothing special about adding Ajax support to a Struts application. Once you understand how to add Ajax support to a regular application, you'll find that adding it to a Struts application follows the same rules: you have a JSP that either calls an Ajax library such as Prototype or DWR or contains your own implementations of Ajax features written in JavaScript. Using an established library such as DWR is more efficient than writing your own Ajaxian code, because it will already have been tested against many browsers and should support browsers that you haven't even tried.

In Chapter 6, we used Scriptaculous to build a shopping application, but that application lacked a way to add new products. Now we'll explore how to use Struts and DWR to add new products to the PRODUCTS table in the database.

Figure 8-4 shows what the application's product management page will look like after the coding in this section is implemented.

The initial view of the Product Manager

Figure 8-4. The initial view of the Product Manager

The DWR framework introduced in Chapter 6 is well suited to working with Struts, and because it automatically generates much of the JavaScript that is needed for Ajax, using DWR minimizes the amount of JavaScript that you need to write.

Let's look back at the database tables we used for the shopping cart example in Chapter 6. The tables are shown in Figure 8-5.

Figure 8-5. The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required