June 19, 2006

Waffle: define a default event in your Action

Waffle now provides a new DefaultEvent method level annotation for use in your Actions. This allows you to mark a particular method as the default event to fire when no other event was signalled. This is particularly useful when a user is directed to a page for the first time. Until now, the previous page was responsible for setting up for the page that preceeds it. Either that or all links within your application would be required to define exactly which event should be triggered through request parameters (e.g. "/application/myaction.htm?EVENT=init|{request}").

The following Action example (MyAction) has its init(HttpServletRequest) method annotated as the default event.

public class MyAction {
@DefaultEvent("{request}")
public void init(HttpServletRequest request) {
// ...
}
}

Notice the value "{request}" set on the DefaultEvent annotation. This provides a hint to Waffle to help it satisfy the method arguments. If you are familiar with Waffle you should realize that this is similar to how events are defined from Views. This in fact is not just similar it is identical. You can define the event arguments for the DefaultEvent annotation in the same way described in the Advanced Events section of the tutorial.