Views

With Waffle you can write views with either Java Server Pages (JSP), FreeMarker or Velocity. Other view technologies, like Tiles or Sitemesh are compatible with Waffle (eg cf our Freemarker example).

Java Server Pages

Using Java Server Pages in Waffle is as easy as it is with other frameworks. You'll be able to reference the Controller that is asscoaiated with the view by the controller keyword. In the jspx example below the getName() method will be invoked from the Controller:

You will also need to set the default view suffix parameter on the WaffleServlet so that actions can be routed to the correct view. The following is an exerpt from the web.xml file:

Note that all view configuration init-params are optional, (and this is why they are left out in some of our examples).

FreeMarker

FreeMarker views can be written like any FreeMarker pages for other web frameworks. For the most part it is best to follow the documentation FreeMarker provides. Similarly to the JavaServer Pages definition above you will need to register the default view suffix accordingly for FreeMarker (typically .ftl).

You will need to register the freemarker.ext.servlet.FreemarkerServlet (or com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet if using in conjunction with SiteMesh) in the web.xml:

Again, see our working Freemarker example.

Velocity

As with the JavaServer Pages and FreeMarker descriptions above you can access the actions from your Velocity script via the action keyword. The example below shows how you should register the Servlet to handle Velocity based pages:

View-Controller Mapping

By default, Waffle uses the controller name as the view name, ie a controller action invoked by "mycontroller.waffle" will be mapped to a view "[view.prefix]mycontroller[view.suffix]", where the view prefix and suffix can be configured via the servlet configuration in the web.xml, as explained above.

Waffle though aims by design to be highly configurable. The org.codehaus.waffle.view.DefaultViewResolver allows the user to fully configure the view resolution. This is achieve via simply key/value properties, which can be either view prefix or suffix keys or the name of the controller. For example, to map "mycontroller.waffle" to, say, "/ftl/mycontroller-view.ftl", we'd simply set in our registrar: