Waffle and 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 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.

  • We import the prototype javascript file to provide the ajax foundation
  • The custom ajax call is new Ajax.PeriodicalUpdater("random", "foobar.waffle?method=random");
  • The first argument "random" refers to the element id tag in the html (the <div>)
  • The second argument foobar.waffle?method=random represents what will be periodically called to the server.
    • foobar.waffle the Action is registered under the key value "foobar".
    • method=random signifies that the "random" ActionMethod method will be called on the Controller.

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.

Partial page rendering

By simply having an ActionMethod invoked through an asynchronous call which return View's you'll be able to build your web applications to take advantage of partial page rendering.

TODO ... need example!!! ...