Musings about Coding, Business and other Geek Stuff Live and Direct from somewhere on the planet
August 27, 2004
Panama vs Cuba Part 2

As trafic is yet again going nuts outside my window. Granma is yet again providing an entertaining bit of reality distortion.

DOZENS of Panamanian workers and university students marched through the capital city’s streets after learning of a possible pardon being granted to the terrorists being held in Panama.

While it is strictly speaking possible that the members of FER 29 the communist student group do work, I think it is safe to say that most “workers” (You gotta love people who still use that term) were more annoyed than anything at the 20 or so students who are out there causing rucus today and yesterday.

I haven’t been out to look yet today, but there is a smell of burning wood in the air. I don’t know if they are having some pro workers paradise bonfire or something.

Posted by pelleb at 03:29 PM
My Panama Photo Blog

John is moving down here from Belgium and bringing his company PhotoBlog with him. We’ll my Photo Blog is now up. Check it out Istmo

John also has some cool Panama shots at PuraVida in particular check todays entry, which is quite funny.

Posted by pelleb at 12:03 PM
August 24, 2004
Panama bloggers meet

Yesterday I met with a couple of new Panamanian residents who are both active bloggers. We had a very interesting couple of beers.

Firstly John Baeyens who is a Belgian entrepreneur. He is the guy behind PhotoBlog, which is a really cool (you guessed it) Photo Blog site. He and the entire company are moving from Belgium to Panama in October. He says in many ways it’s a logical choice as they have many clients in Latin America.

Secondly Willy who is the guy behind A42.com. He is another very interesting guy, who has lived all over the world. He recently moved here from Costa Rica. Willy is an avid OSS/Linux fanatic, it’s good to see more like this here.

The conversation was long and varried about everything from life in Panama, to economics and politics. John mentions that no one back home in Belgium can quite understand why he’s leaving and why he’s going to Panama.

For me it’s not just the weather and the low cost of living, it’s something much more fundamental about personal freedoms. As an expat you always give up some freedoms you are used to at home, but you generally achieve a much greater freedom than you can ever have at home in a place filled with many expectations about who you should be and how you should act.

I am happy to say I’m a chronic expat. I left Denmark when I was 20 (14 years ago). So I don’t really have many of those expectations hanging over me.

Anyway another reason that we all like Panama is that it is so cosmopolitan. We literally have people here from every country in the world. You yourself choose to what extent you integrate in society. But no one wonders why you are here.

Posted by pelleb at 05:05 PM
August 22, 2004
Quake

So at 11:54 last night I was sitting on my bed watching TV, when all of a sudden the bed started moving. It kept moving and moving for what seemed like an eternity. No, it wasn’t the beans I ate last night having an effect on me, it was an earthquake. The excellent USGS site lists it at 4.6

Here in the city we don’t get a lot of big ones. In Chiriqui closer to the border with Costa Rica there are quite a few and there is always lots of damage.

I’m from Denmark which is probably one of the most seismically inactive places in the world, so this is still pretty exciting for me. We had a stronger one last year, which I pretty much slept through, so it was cool to actually get to experience this through out. My wife being from Chiriqui hardly notices them.

Posted by pelleb at 03:11 PM
August 20, 2004
3 steps to speed your KDE3.3 build

I’m sure by now that all KDEophiles know about the new KDE 3.3 Release. For those of us using Gentoo or just plain like building from source (you know who you are), a new KDE release fills us with excitement, but also a slight annoyance that we need to leave our machine overnight (or over weekend) building in the back ground. Particularly those of us with old machines. I use an ancient Dell Inspiron 5000e with a 700Mhz P3.

The good news is that there are now 3 little tools that you can use to speed up the build process. If you use Gentoo it’s super easy. If not, it’s not really that much harder. Actually this should speed up the build process of most larger c/c++ based unix projects as well.

Step one - Unsermake

Unsermake is a new addition to the build process of kde. I think it should be made the default option and my guess is it probably will at some point.

Unsermake replaces automake and all the billions of tiny Makefile’s that get called recursively with one large Makefile. It is completely transparent to the kde build process. I’m sure you could use this for other projects, but I’ll leave that to you.

There are several benefits to this single Makefile approach:

  • It only has to recurse through everything once and not for each phase of the build process.
  • It allows make to do what it does best, handle dependencies globally.
  • It allows make to handle the forking of compile process in a much more efficient way, which we will see helps us when we get to distcc below.

Gentoo approach

# emerge unsermake
#  echo "UNSERMAKE=\"/usr/kde/unsermake/unsermake\"" >/etc/env.d/46unsermake
# export UNSERMAKE="/usr/kde/unsermake/unsermake"

The second step adds an environment variable for future use, letting KDE know where it is. While the last one just quickly sets the value for use right now.

All others

I haven’t tried this, but just I think it’s pretty simple. You just have to dowload the latest unsermake build and unpack it somewhere. It is written in Python and doesn’t have any need for it’s own build process. So try this:

# wget http://msquadrat.de/pub/softlib/unsermake/unsermake-0.3.0.4224.0.tar.bz2
# tar xjvf unsermake-0.3.0.4224.0.tar.bz2
#  export UNSERMAKE=[CURRENTDIR]/unsermake-0.3.0.4224.0/unsermake

Then start the KDE Build proces.

Step 2. Don’t cough, ccache

You know the annoying feeling when you are 3 hours into a build process and it dies on you, because of a missing dependency. Or let’s say you want to change the configuration of it and rebuild it. ccache is a lifesaver in these situations.

You can basically think of it as a caching proxy c compiler. It just sits in front of your gcc and caches our returns a previously cached version of the output of the real compiler. I believe it builds up a hash of the compiler flags as well as the source files. If it’s a match to something already in the cache it returns it, thus skipping the recompile. This itself can cut masses of time off a recompile.

Gentoo approach

# emerge ccache

Then edit your /etc/make.conf file so it has ccache listed under the FEATURES section:

FEATURES="{OTHER ENTRIES} ccache"

Thats all ther is to it.

Others

# wget http://ccache.samba.org/ftp/ccache/ccache-2.3.tar.gz
# tar xzvf ccache-2.3.tar.gz
# ./configure
# make
# su
# make install
# mkdir /usr/local/ccache
# ln -s /usr/local/bin/ccache /usr/local/ccache/gcc
# ln -s /usr/local/bin/ccache /usr/local/ccache/cc
# ln -s /usr/local/bin/ccache /usr/local/ccache/g++

Now it is installed. To actually use it you must either change the CC variable in the Makefile you’re using to use /usr/local/ccache/gcc or put the /usr/local/ccache in your path before the real gcc. eg.

# export PATH=/usr/local/ccache:$PATH

Now configure and build to your hearts content.

Step Three - Take a load off your back with distcc

My poor notebook. Great screen, new harddrive maxed out memory but only 700MHz. Thankfully I have an Athlon desktop sitting beneath my desk (actually dining room table) without a monitor (no space). This is my local server which I use to offload lots of stuff.

Enter distcc which comes from the same team that developed ccache above. It basically offloads compiler processes to other machines in the network. Thus speeding things up drastically. In particularly if you use it with unsermake.

You do need to install distcc on all your machines and a fastish net is probably a good idea. I wouldn’t necessarily recommend using it over a WIFI connection, but thats just an educated hunch.

Planning

First you need to write down the ip addresses of the machines you want in your super compiler cluster. I for one have only 2. Let’s for sake of argument say my notebook has IP 192.168.0.10 and my server 192.168.0.20

Gentoo Approach

  1. emerge distcc
  2. /etc/init.d/distccd start
  3. distcc-config —set-hosts “192.168.0.10 192.168.0.20”

As my main machine is slower than the server I list the server last, so it gets most of the load.

Now do the same on the other machine[s] in your network.

Edit your /etc/make.conf file like you did with ccache above and add distcc. Your file should now look something like this:

FEATURES="ccache distcc"

Now everytime you emerge something it gets sent first via ccache and onwards to distcc which distributes the load around your network.

Others

Very similar to installing ccache:

# wget http://distcc.samba.org/ftp/distcc/distcc-2.17.tar.bz2
# tar xjvf distcc-2.17.tar.bz2
# ./configure
# make
# su
# make install
# mkdir /usr/local/distcc
# ln -s /usr/local/bin/distcc /usr/local/distcc/gcc
# ln -s /usr/local/bin/distcc /usr/local/distcc/cc
# ln -s /usr/local/bin/distcc /usr/local/distcc/g++

Now you can start it up on the servers with:

  1. distccd —daemon

Put the list of hosts in /etc/distcc/hosts eg.:

  1. echo “192.168.0.10 192.168.0.10”>/etc/distcc/hosts

To use it do the same as for ccache, just make sure that ccache’s cc is infront of distcc in the path:

# export PATH=/usr/local/ccache:/usr/local/distcc:$PATH

An easier way to distribute load without installing.

I haven’t tried this these guys have a new bootable cd with distcc, that you can download, burn onto a cdrom and boot up on your various pc’s that aren’t running linux. No install needed. Pretty cool.

Disclaimer

I only really use Gentoo, so I haven’t tested out the non gentoo instructions thoroughly. If you see any glaring errors let me know.

Posted by pelleb at 01:44 PM
Ramblings about Rain

John Bayens is arriving here I think tomorrow night. I hope he’s remembered his umbrella as the rain is pretty damn intense at the moment.

When you consider the amount of rain we have here during our 9 month “winter” period you have to wonder how they managed to get the canal finished. The rain caused mudslides that killed thousands of workers. Speaking of which, Sunday was the 90th aniversary of the Canal. I think this still counts as one of the greatest construction feats ever. It has been such a benefit to the world that we must really thank the tens of thousands of people who came from all over the world to build (and many die while doing so) the canal.

Posted by pelleb at 12:49 PM
August 19, 2004
Epitafios - A superb Argentinian series

I am normally not one to rave about tv programs, but Epitafios a new series from HBO Latin America is so far outstanding. It is a 13 part very gory serial killer/revenge story. Think Seven and Silence of the Lambs, mixed with 24.

I finally got to see the first episode and it blew me away. Each episode is 1 1/2 hours. How the hell did they manage to get budget to do 13 whole episodes? And everything is excellent from the effects and make up to the acting and cinematography.

To get an idea go check out the very well done (Flash) Epitafios web site. The way the killer kills his victims is like a more extreme version of what Brad Pitt and Morgan Freeman were up against in Seven.

The plot is based around a cop who was at the scene of a hostage crisis in a high school. A teacher had taken 4 students hostage and poored gasoline on them. When the hero tries to rescue them, he makes a mistake and the teacher lights his students who go up in flames in front of everyone. This is now several years later and the serial killer is trying to revenge himself on everyone who had anything to do with that incident. The cop himself feels very guilty himself, which adds an interesting edge to his role.

The name of the series comes from the fact that the killer announces his intent to murder someone on the epitaphs of grave stones that he sends the police.

All in all very cool stuff. I’m sure they will be exporting it to markets outside Latin America, so keep an eye out. It will probably be called Epitaphs in English.

Posted by pelleb at 12:57 PM
Hey, who is playing galaxians outside my windows?

Last week I’ve noticed for the first time near my apartment the distinctive sound of a late 70’s space shootemup laser. It’s coming from the empty plot opposite my building.

Are aliens attacking Panama or is it just some geek running MAME on his cellphone. It turns out none of the above. The sound is produced by a tiny frog that is very common here in Panama. When I first heard it a couple of years ago, I couldn’t believe my ears. It sounds so much like something generated by a 70’s model VCO it’s uncanny. Of course here in the city we just get a few patches where we can hear them. If you go further out it gets really intense.

When I went to El Valle in the mountains a couple of hours from here it positively sounds like a 1981 version of a Demo Party

So I’m glad to finally have my own little amphibian demo party next doors. Maybe I should send them pizza and coke tonight?

Posted by pelleb at 12:36 PM
August 14, 2004
6 Simple Rules for Micro Ventures

Over on EconoTrix I’ve been working on some ideas for how small geek run projects can be promoted to bring either financing or partners into help them out. Many of us run a bunch of small essentially electronic micro businesses, whether it is just the monthly Google Ad check or some ecommerce deal.

The rules are:

  1. Focus on one and only one clearly defined economic activity.
  2. Distribute revenue early and often.
  3. Attempt to eliminate the burn rate.
  4. Pay stakeholders with shares, not salary.
  5. Keep a flat democratic command structure.
  6. Fund capital costs seperately from the fixed costs.

To read more about why see the full article The Electronic Micro Venture or for just a more detailed description about the rules themselves see: 6 Simple Rules for Micro Ventures

Posted by pelleb at 01:01 PM
August 11, 2004
Panamanian Women are Hot

Seen in the latest issue of Wired :

On our way out the door to visit the lab where the DNA is sequenced, Pfannkoch opened a huge freezer; stored inside at -112 degrees Fahrenheit were Hoffman’s labeled pouches. She took out a bag and rubbed the thick layer of frost off the label with a finger. In addition to the ID, it read: Panamanian women are hot.

Craig Venter’s Epic Voyage to Redefine the Origin of the Species

What can I say he is so right. I for one married one myself and am very happy. See for yourself what you might experience on an average night out in Panama City.

Posted by pelleb at 12:59 PM
Extending NanoWeb with Prevayler

I am a fan of cool simple technology. Prevayler and NanoWeb both count as this. They are both relatively transparent and have been implemented with tiny amounts of code.

I have several smaller web projects that I’m working on, where I want to use both of these technologies. Which is why I’m adding the stuff I need.

After finishing the implementation of adding multiple views to NanoWeb yesterday. I was thinking about how I could use Prevayler with NanoWeb. I came to realize that it could be done very simply with a few changes to the NanoWebServlet.

I don’t really want to add too much more functionality to NanoWebServlet, so as a quick Hack I created PrevalentWebServlet. What you do when you write an action is implement either or both org.prevayler.Query or org.prevayler.Transaction. Actually I extedned Transaction to be ValidatingTransaction, which adds a isValid() method.

If the action implements Query prevayler processes the query before handling the action method. If it implements Transaction and has been marked by the action method as valid it processes the Transaction.

Here is an example:

public class PersonEditor implements ValidatingTransaction, Query{
     private String name;
     private String address;
     private String email;
     private String comment;
     private transient boolean exists=false;
     private transient String message;
 
 
     public String  view(){
          if (!exists){
               return edit();
           }
          return "view";
      }
     public String edit(){
          if (email==null)
              email="";
          if (name==null)
              name="";
          if (address==null)
              address="";
          if (comment==null)
              comment="";
          if (exists)
              return "edit";
          else
              return "new";
      }
     public String search(){
          if (email==null)
              email="";
          return "search";
      }
     public String getName() {
          return name;
      }
 
     public void setName(String name) {
          this.name = name;
      }
 
     public String getAddress() {
          return address;
      }
 
     public void setAddress(String address) {
          this.address = address;
      }
 
     public String getEmail() {
          return email;
      }
 
     public void setEmail(String email) {
          this.email = email;
      }
 
     public String getComment() {
          return comment;
      }
 
     public void setComment(String comment) {
          this.comment = comment;
      }
 
     public String getMessage() {
          return message;
      }
 
     public void executeOn(Object o, Date date) {
          Map map = ((Map)o);
          if (map.containsKey(email)){
               Person person=(Person) map.get(email) ;
               person.setName(name);
               person.setAddress(address);
               person.setComment(comment);
           } else
              map.put(email,new Person(name,email,address,comment));
      }
 
     public boolean isValid() {
          return (name!=null&&email!=null);
      }
 
     public Object query(Object o, Date date) throws Exception {
          if (email!=null){
               Person person=(Person) ((Map)o).get(email);
               if (person!=null){
                    exists=true;
                    if (name==null)
                        name=person.getName();
                    if (address==null)
                        address=person.getAddress();
                    if (comment==null)
                        comment=person.getComment();
                    return person;
                }
           }
          return null;
      }
}

Of course this was written in Java. Would Groovy be an option for this as well? I am guessing that yes you should be able to write Prevayler Transactions and Queries in Groovy. But I don’t know. Perhaps someone would like to take a shot at it?

I’m not 100% convinced this is all good thing so far. It probably lends itself best to very simple applications. I definitely need to clean up the implementation of it. Maybe adding somesort of PersistanceManager to NanoWeb. I don’t know, then we would be making a nice simple library more complex.

If you want to try it I’ve put up a war file containing a sample prevalent web application

Posted by pelleb at 12:34 PM
August 10, 2004
JSP support for NanoWeb

As mentioned in my last post about NanoWeb I wanted to add support for other view types. Well that I have now done. It’s been submitted to the nanocontainer jira, where you can download it if you want it. I have also updated my last posts NanoWeb Sample WAR to include this and samples on how to use it. Just download and drop into your tomcat/webapps folder.

Configuration

The default view type is still velocity, but to add others such as JSP add the following init-param in the web.xml.

<servlet>
	<servlet-name>NanoWeb</servlet-name>
        <servlet-class>org.nanocontainer.nanowar.nanoweb.NanoWebServlet
	</servlet-class>
        <init-param>
            <param-name>viewtypes</param-name>
            <param-value>.jsp,.vm</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
</servlet>

Just list the extensions to the view technologies you want to use. While not tested this should also work for freemarker.

In the above example it will first look for .jsp views and then try .vm views.

Using POJO as NanoWeb Actions

I hadn’t realized this, but Aslak mentioned that there was already support for plain Java actions. It turns out that all you have to do is register it to the Request scope of the PicoContainer in your web.xml file:

pico.registerComponentImplementation("/salary",org.nanocontainer.sample.nanoweb.SalaryCalculator)

The Java class itself couldn’t be simpler. Just implement properties with setters and getters. All methods without parameters that return a String can be called via the web as actions.

Here’s a simple example:

public class SalaryCalculator {
     private String name;
     private String salary;
 
     public String getName() {
          if (name==null)
              return "Enter name";
          return name;
      }
 
     public void setName(String name) {
          this.name = name;
      }
 
     public String getSalary() {
          if (salary==null)
              return "0";
          return salary;
      }
 
     public void setSalary(String salary) {
          this.salary = salary;
      }
 
     public String getMonthlySalary(){
          return Double.toString(Double.parseDouble(salary)/12);
      }
 
     public String calculate(){
          if (name==null||salary==null)
              return "input";
          else
              return "view";
      }
}

This certainly is simple. Just make sure you don’t add any exploitable methods in your actions such as:

public String transfer() {
 	queue.publish(new Transfer(getAmount(),getRecipient()));
}
Posted by pelleb at 04:03 PM
August 04, 2004
Introducing the NeuClear Account

With NeuClear we are trying to really do something really distruptive. We want to completely invert the relationships people have with financial institutions and other companies. Doing this means doing things very differently than what people are doing today.

Telling people about this has proved much harder than we probably initially thought. The main reason I think is that people are so used to financial institutions etc. being in positions of authority and that these things can never be changed nor questioned the same way we question everything in the tech world.

So, I’ve started a new high level consumer oriented site for NeuClear.com as opposed to the geek oriented NeuClear.org site. One of the first articles is about the new Self managed NeuClear Account.

The NeuClear account is an account that you control. You can think of it a bit like an account at an online brokerage account containing many different kinds of stock, except in reality the account is on your own computer.

You can create as many accounts as you want. However you can seperate them by purpose and not by content as you would do right now. For more information on why you would want more than one account see this about Networked Economic Units.

Posted by pelleb at 09:57 AM
August 02, 2004
How to get started with NanoWeb

Since I first read about NanoWeb a couple of months ago, I’ve been fascinated by it’s easy approach. Unlike any other java mvc framework there are no g’damn xml configuration files.

One of the problems with NanoWeb is that it is not very well documented. Like much of the innovative stuff happening at codehaus they refactor at will, which they should definitely do with experimental stuff like this. They have also just recently moved everything around in CVS. NanoWeb and a few other related projects have now been merged under a new project NanoWar where all the development is taking place now. NanoWar includes NanoContainer like configuration of Struts, Axis, Webwork 1 &2 as well as of course nanoweb.

They have a Sample NanoWeb that you can checkout from CVS and build with maven. I’ve been playing around with it a bit over the weekend and wrote my own extremely useless personel web application using it. You can download a working NanoWeb Sample Application WAR here which includes their game sample (with my cheat hack) and my personel application. Just drop it in /opt/tomcat/webapps (you know the score).

I will now go over some of the basics of nanoweb configuration and development:

Configuration

We all hate configuring stuff in J2EE right? Well judging by the sheer amount of xml configuration files going on in your average struts, spring, webwork etc, etc framework yall gotta be loving it now. Well I can’t stand it. I’ve got a perfectly good Java IDE, I’m a semi capable java developer. For god’s sake let me write code and not spend half my life in xml.

I’ve always been a fan of PicoContainer as it allows me to build configurable apps without all the extra imports and external configuration files. PicoContainer let’s you configure stuff in Java. NanoContainer extends that and lets you configure stuff in xml or your favorite scripting language. No change needed in your code.

NanoWeb is part of NanoContainer and lets you configure your PicoContainer’s within your web.xml file using Groovy or any other java scripting language:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>NanoWeb Demo</display-name>

    <context-param>
        <param-name>nanocontainer.groovy</param-name>
        <param-value><![CDATA[
             pico = new org.picocontainer.defaults.DefaultPicoContainer(parent)
            if(assemblyScope instanceof javax.servlet.ServletContext) {
		pico.registerComponentImplementation(java.util.Map,java.util.HashMap)
            } else if(assemblyScope instanceof javax.servlet.http.HttpSession) {
                // Session level components
                pico.registerComponentImplementation(org.nanocontainer.sample.nanoweb.NumberToGuess)
            } else if(assemblyScope instanceof javax.servlet.ServletRequest) {
		
            }
        ]]></param-value>
    </context-param>

    <listener>
        <listener-class>org.nanocontainer.nanowar.ServletContainerListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>NanoWeb</servlet-name>
        <servlet-class>org.nanocontainer.nanowar.nanoweb.NanoWebServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>NanoVelocity</servlet-name>
        <servlet-class>org.nanocontainer.nanowar.nanoweb.NanoWebVelocityServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    
    <servlet-mapping>
        <servlet-name>NanoWeb</servlet-name>
        <url-pattern>*.nano</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>NanoWeb</servlet-name>
        <url-pattern>*.groovy
        </url-pattern>
    </servlet-mapping>

    
    <servlet-mapping>
        <servlet-name>NanoVelocity</servlet-name>
        <url-pattern>*.vm</url-pattern>
    </servlet-mapping>
</web-app>

The above is the web.xml file used in the sample app. The top part is an inline groovy script to configure PicoContainer for each of the possible scopes within a J2EE web app.

You simply register classes (and implementations) in the PicoContainer for each scope. Application (ServletContext), Session or Request. In the above, I have registered a HashMap under the Application context. This is my Personel database (I told you it was simple). As part of the game demo there is a NumberToGuess class registered for the Session. The game keeps track of who’s playing using this session scope object.

Creating your App

So how do you write your actual app? Firstly create a groovy class directly in the web apps. Each method within that class is an action. So an example URL for the file game.groovy is /game/play.groovy

Each method doesn’t take any parameters. You define local variables in your class and put any required components from the PicoContainer we configured earlier in the Constructor. This allows PicoContainer to easily auto configure the app automatically. For each method you must return a View name. Just return a string like “view”.

class Person {
 	name=""
 	age=0
 	java.util.Map map
 
 	Person(java.util.Map database) {
  	   map=database;
  	   if (name!=""&&age==0) {
   		age=map.get(name)
   	   }
  	}
 	
 	enter() {
  		if (age==0&&name!="")
  			age=map.get(name)
  		return "input"
  	}
 	
 	search() {
  		return "search"
  	}	
 	register() {
  		if (name==""||age==0) 
  			return "error"
  		map.put(name,age)
  		return "success"	
  	}
 	view() {
  		if (name=="")
  			return "error"
  		age=map.get(name);
  		return "view"
  	}
 
 	list(){
  		return "list"
  	}		
}

I am no Groovy expert. As a matter of fact this was my first attempt at groovy and I have no idea what I’m doing, but it seems easy enough. It appears I can just write Java but I don’t need semi colons and it’s not vital to declare variable types.

Views

As you can see above several of the actions just simply go straight to a view. So what is a view? The current implementation just uses velocity templates. I’ve looked at the code and it should be simple enough to add jsp and friends to it as well. The only requirement for using velocity and not jsp is that the extension .vm is hardcoded in the NanoWebServlet at the moment.

Simply speaking you create velocity templates which are resolved using the following naming structure:

  • /context/folder/script_action_result.vm
  • /context/folder/script_result.vm
  • /context/folder/result.vm
  • /result.vm

Where “result” is the string you return from your action method. Action is the method name and script is the name of the script.

Here is an example of a simple view register_list.vm which lists the contents of the HashMap:

<html>
    <body>
<ul>
#foreach( $key in $action.map.keySet() )
    <li><a href="view.groovy?name=$key">$key</a></li>
#end
</ul>
<a href="enter.groovy">Add new person</a>
    </body>
</html>

As you can see you can access the Groovy classes instance variables through the $action variable within velocity.

End thoughts on NanoWeb

NanoWeb is very simple as it is, both to write for as well as the actual implementation, which consists of 5 classes and one interface. The main addition I would make to it is add jsp and freemarker as supported views ( I might have a go at that myself).

Secondly and probably less important is to add other languages to it. I would like to be able to write real java code and not just groovy. The reason being that IntelliJ IDEA could then help me be a bit more productive. If we did that we might as well add support for Python and Ruby as well. Who knows I might try my hand at that as well.

Please, please don’t start adding extra fluff like AOP, Validation etc to it though. Keep it simple. Let people add their own fluff. That is what annoys me with things like webwork. It is far more complex than it needs to be. The thing I really like about NanoWeb is the ASP/PHP like simplicity it brings to real MVC.

Posted by pelleb at 10:51 AM