Ajax

Waffle was built to be easy to develop with and this ease extends to Ajax support as well. Utilizing Ajax in Waffle application is straightforward and simple. The examples here use the well known Prototype JavaScript Framework.

Ajax Controller

We will create a simple Controller with an event (int random();) that will return a random number between 0 and 10. To make it more interesting whenever the value equals 5 the event will throw an Exception.

Ajax-ified View

So we create a simple View that will periodically (every 2 seconds is the default) request a new value from the Server.

Wire it up with the Registrar

The FoobarController is registered under the name "foobar". Notice that the Controller is being registered to the Application level context.

The document that comes back over the wire per Ajax request, is a one-line toString() transformation on the int result of the random() method. This is performed by org.codehaus.waffle.action.ActionMethodResponseHandler.