concept Ajax in category grails

appears as: Ajax, Ajax
Grails in Action, Second Edition

This is an excerpt from Manning's book Grails in Action, Second Edition.

If you’re writing a small application, you may as well have fun. This example is a Quote-of-the-Day web application in which you’ll capture and display famous programming quotes from development rock stars throughout time. You’ll let the user add, edit, and cycle through programming quotes, and add a dash of Ajax sizzle to give it a modern feel. You’ll want a short URL for your application, so make qotd your application’s working title.

In this chapter, you’ll focus on the front end. You’ll cover the basics of putting forms together, and you’ll investigate how to support multiple browsers with reusable layouts. You’ll explore Grails’s handy new resources infrastructure which manages all your visual assets. You’ll also turn your attention to visual effects and implement slick animations and Ajax interactions. By the time you’re done, Hubbub will sparkle.

At this point, you also need to update the layout because you’re using the Resources plugin. If you don’t add the following lines (in italics) to main.gsp, the relevant JavaScript code won’t appear in your pages and the Ajax won’t work!

Listing 8.10. Updating the layout

With your library selected and the Resources plugin primed (we’ll talk more on this in chapter 13), you can now update the posting form to submit the Post contents remotely. Grails provides the <g:submitToRemote> tag to bundle the contents of a form and send it via Ajax to a back-end service. The following listing shows the updated form definition.

Listing 8.11. Adding a new Post via Ajax

8.4. Applying Ajax tags

We’ve saved the best UI work for last. In this section, you’ll use Ajax to take the Hubbub UI experience to a whole new level. You’ll get a taste for dynamically changing your Hubbub page in-place using remote calls to back-end code. Then you’ll create visual sizzle with JavaScript animation and effects.