Print
NanoWar NanoWeb

Article

Pelle Brændgaard has written an excellent article.

Introduction

NanoWeb is a simple and powerful dynamic MVC framework based on Java servlet technology,Groovy and Container. NanoWeb borrows many ideas from WebWork and Struts, most importantly the concepts of actions and views. Its main difference from these frameworks is that it is 100% dynamic and requires no configuration beyond mapping of to servlets in web.xml.

The NanoWeb framework attempts to do fewer things than the frameworks it is inspired from. It focuses uniquely on action execution (the control part of MVC) and view redirection (the View part of MVC).

It is the dependency injection mechanism provided by [PicoContainer] that allows NanoWeb to be as simplistic as this. Web applications written for NanoWeb can leverage existing frameworks for additional services such as [Validation] and hook them into the actions via dependency injection.

100% dynamic

NanoWeb lets you write 100% dynamic webapps. In theory you can fire up your servlet container and add actions and views as you please without having to restart the container or reconfigure the webapp. Let's have a look at a NanoWeb action written in Groovy:

An error occurred: http://svn.codehaus.org/picocontainer/java/nanocontainer-nanowar/trunk/nanowar-sample/webapps/nanoweb/webapp/game.groovy. The system administrator has been notified.

Assuming that this source file lives under the webapp at the following relative location:

game.groovy

Then you would be able to execute the play action by accessing the following URL:

Groovy action method    ----------------------------------+
Groovy action class     -----------------------------+    |
Web app root            -----------+                 |    |
Servlet container                  |                 |    |
         |                         |                 |    |
         |                         |                 |    |
<--------+----------> <------------+-------------> <-+-><-+->
http://localhost:8080/nanocontainer-sample-nanoweb/game/play.nano

You would place this groovy source somewhere under the root of your webapp (along with the view pages). If your servlet container is configured to look at your source directory, it will pick up and recompile the Groovy actions if you change them. (As any other Servlet-based web application you can of course package everyting in a war too).

For views you can use Velocity. (We're planning to add support for Groovy Templates, FreeMarker and plain old JSP too. (Contributions from the community are welcome).

No configuration

NanoWeb requires no application-specific configuration when using Groovy for actions. (They are automatically URL-mapped to their relative location under the webapp root).

Still, it is possible to configure NanoWeb using the common configuration schemes provided by the NanoServlet component (http://docs.codehaus.org/display/NANO/NanoContainer+Servlet).

Naming conventions

The association of views to actions is based on naming conventions rather than on configuration. Less configuration pain for the developer.

Dependency injection

All actions (including Groovy ones) can benefit from dependency injection (via PicoContainer).

Non intrusive

NanoWeb actions don't have to extend or implement anything. Reusable functionality will be leveraged through constructor injection-backed delegation rather than inheritance.

Technology

NanoContainer builds on the following libraries and frameworks:

  • picocontainer (provides the dependency injection service for NanoWeb actions and also app/session/request level scoped data)
  • nanocontainer (provides scripted configuration framework for picocontainer)
  • velocity (for views. will add support for freemarker too, so people can use existing jsp taglibs)
  • groovy (optional action language for 100% dynamic webapps. can also be used for embedded pico configuration inside web.xml).
  • ognl (for adressing data reachable via the action, from the velocity views).

Download

Get a nanocontainer-nanowar jar file from the downloads page or direct from the Maven repository http://dist.codehaus.org/nanocontainer/jars/

Powered by Atlassian Confluence