Example: Hello World

Our first example is the obligatory Hello World. However it'll provide a good overview on how simple it is to create Waffle web applications. The process can be broken down into 3 simple steps:

  1. Create a Controller
  2. Register that Controller with the Registrar
  3. Create the View

Controller

The Controller object which will be responsible for handling user requests. This class is simply a POJO and is not required to extend from any Waffle base classes. The Controller below below does NOT have any ActionMethods.

Registrar

All Controllers need to be registered with Waffle. This is done through the Registrar. Line 9 in the MyRegistrar class below registers the HelloWorldController under the name "helloworld". This Registrar will need to referenced in the web.xml.

View (helloworld.jspx)

A View in Waffle is no different than what you would expect from any Java based web framework. Waffle exposes the underlying Controller for use in your View under the key controller. Notice line 12 ${controller.greeting}, this is calling the greeting property exposed in the HelloWorldController.

The example below uses jspx but FreeMarker and Velocity are also supported.

You may also want to add a JSP redirect from the index welcome page to the hello world controller:

Running...