build: 309
updated: Jun 17 2008 Jodd Library
Community
Project Reports
Jodd
Jodd-WOT
|
Madvoc
*There is only one difference between a madman and me. I am not mad. (Salvador Dali)
Table of Contents
Madvoc is MVC framework that prefers convention over configuration what removes the need for external configurations. The story behind Madvoc is not new: it is similar to VRaptor and WebWork2/Struts2. Madvoc controller on each request creates a new instance of action, invokes it and renders the view indicated by action result. Madvoc actions are simple POJO classes. Each action can be intercepted by one or more interceptors. There is only one default interceptor, that injects and outjects parameters and attributes to and from the action before and after action execution. This is default behavior which will be explained bellow. Highlights
Core
Sorry, documentation is not yet complete and does not provide sufficient information. Please refer to test cases, javadoc and sources for more details.
If you need more info on this particular subject, do not hesitate to demand more documentation. It is important to separate the core Madvoc behaviour from its configuration! Core functionality is the concept itself how Madvoc works, and it is something that is less changeble, but still configurable. On the other hand, default configuration in Madvoc is very changeble, so every user can define its own way how to configure Madvoc: using annotations, XML files, plain Java, or whatever suits him the best. Actions
On each request, Madvoc creates one action object and invokes it. An action encapsulates the request. In Madvoc actions are defined by:
Actions are good old POJOs. If default interceptors are used (and there is no reason why not), actions will usually contain some annotations. Here is a typical action: @MadvocAction @InterceptedBy(MyInterceptorStack.class) public class HelloAction { @In private String name; public void setName(String name) { this.name = name + "xxx"; } @In MutableInteger data; @Out String retv; public String world() { System.out.println(">HelloAction.world " + name + data); retv = " and Universe"; return "ok"; } The name of all actions classes must end with ' Similarly, destination to which results are mapped depends also on string value of action handler result. In above example there is only one destination, and by Madvoc convention it is: ' For convenience, some action handlers with common names do not use method name in action path: Parameters
As expected, parameters are injected and outjected to and from action. Annotation Interceptors
Actions may be intercepted. As said, by default, two interceptors are active: one that renders the results, and the other that prepares action and performs injection and outjection. Interceptors may be applied to action class, but also to action handlers (i.e. methods). Default interceptors don't have to be stated, so when adding new interceptors, it is possible to simply add all default ones, at once. Interceptors are singletons for one Madvoc. Since interceptors are invoked on each action, due to performance, parameters are not dynamically injected into it. Configuration
Custom mappings and naming
Naming convention is nice, but sometimes users may want to override it. Of course, it is very easy to do, within annotations: @MadvocAction("/foo/boo") public class CustomAction { @In("ppp") List<Person> plist; @In("ppp") Person[] parray; @In("ppp") Map pmap; @Action("/foo/hello") public String execute() { // mapped to /foo/hello (no default extension!) return "ok"; // mapped to /foo/hello.ok.jsp } @Action("zoo/again.exec") public void again() { // mapped to /foo/boo.zoo/again.exec.html System.out.println("CustomAction.again"); // mapped to /foo/boo.zoo/again.exec.jsp } @Action("/foo/boo-aa/temp.bb") public void temp() { // mapped to '/foo/boo-aa/temp.bb' } Result types
Results may be of various types. By default, there are dispatching and forward types, but it is easy to add more types. For example, it is possible to add custom result type for rendering FreeMarker or Velocity templates, or to generate PDF reports. public String fff() { return "forward:/hello.again.html"; } Direct output & Servlet classes
It is easy: @In(scope=ScopeType.CONTEXT) HttpServletResponse servletResponse; public String again() throws IOException { // mapped to /hello.again.html servletResponse.getWriter().print("Direct stream output..."); return "none:"; } This is also an example how references to HTTP classes can be injected in the action, by using specific scope type. Upload
Uploaded files are injected as input parameters: @MadvocAction public class UploadAction { @In UploadFormBean foo; public String exec() { System.out.println(foo); return "ok"; } } Configuration
Madvoc dispatcher is registered as filter in 'web.xml'. By default it uses automatic mode that scans the class path for action classes, interceptors etc. It is possible to fine tune this search, if needed. Moreover, Madvoc will search also for Petite
Madvoc can be easily integrated with Petite. Such integration makes development power and yet simple. |