Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

No XML, please!

A small, flexible, and easy MVC Web framework with no XML

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Some people like olives. Some don't. I don't like olives. I don't like XML either. Unfortunately, for me, all major Web frameworks rely on XML to do basically everything: setup, configuration, form handling, validation, etc. Welcome to the world of XML "programming."

Another problem for me is that I like to do things really fast. That's why I had a feeling something was wrong with C++. To do a project with C++, medium programmers end up spending more than half their time fighting with the language syntax, pointers, handlers, memory management, unbound arrays, etc., and very little time doing what they're paid to do: the project. The Java language comes to the rescue with an abstraction power that makes everything easy. Whatever pops into your head—Java can do it! You don't have to care how, you just have to use the APIs.

Unfortunately, the Web frameworks out there are not for the medium guys. They require time to master and can scare rookies with XML all over the place and little tricks they are expected to know and get away with. It is like showing a Hello World EJB example to someone that has never seen an Enterprise JavaBeans component before. The result is shock and fear.

Mentawai, an open source framework, tries to break free from this scenario by implementing a small, simple, flexible, idiot-proof MVC (Model-View-Controller) Web framework with no XML at all. Instead of XML, we can use Java code to achieve the same results, and guess what: Java code has Javadocs! You can even compile Java code to catch errors! Java code is object-oriented programming. How about XML?

The most common reply I get from people when I defend this point is: "Hey, you don't have to compile and restart your Web application with XML!" I may be losing something deeper here, but, if you change your XML, you do have to restart your Web context for most of the Web frameworks I have seen. Plus compiling is definitely not a bad thing. It is a good thing! If you could compile XML to quickly discover a wrong attribute, our debbuging time would decrease.

Now that I have argued my point, let's check what Mentawai can offer us as an alternative.

Setup

Let's begin by setting up our Web application to use the Mentawai framework. First, place the mentawai.jar file (downloadable from Resources) inside your application's /WEB-INF/lib directory and declare in your web.xml file that you want to use the Mentawai controller:

 <!-- The Mentawai controller -->
<servlet>
   <servlet-name>Controller</servlet-name>
   <servlet-class>org.mentawai.core.Controller</servlet-class>
   <load-on-startup>1</load-on-startup>
</servlet>

<!-- You must choose an extension to indicate a mentawai action --> <servlet-mapping> <servlet-name>Controller</servlet-name> <url-pattern>*.mtw</url-pattern> </servlet-mapping>


The action paradigm

Mentawai uses the action paradigm. The main characteristics of a Mentawai action are:

  • An action has an input (org.mentawai.core.Input) and an output (org.mentawai.core.Output).
  • An action generates a result (java.lang.String) after it executes. The result is usually SUCCESS or ERROR, but you can create your own.
  • For each result, there is a consequence (org.mentawai.core.Consequence). Consequences for a Web application are usually FORWARD or REDIRECT, but you can create your own.
  • An action has access to contexts (org.mentawai.core.Context). Contexts for a Web application are usually a session context (org.mentawai.core.SessionContext) and an application context (org.mentawai.core.ApplicationContext), but you can create your own.

Let's see an example Mentawai action:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources