Echo3Groovy

With minor changes to the echo3 codebase, it is possible to use [WWW] Groovy to create echo3 classes, and take advantage of the terse syntax and first-class javabeans support that it provides.

  1. Example groovy source
  2. Applying the patch
  3. Downloading the patches

Example groovy source

package org.sgodden.echo3.testapp.groovy;

import nextapp.echo.app.Button;
import nextapp.echo.app.Color;
import nextapp.echo.app.Extent;
import nextapp.echo.app.Grid;
import nextapp.echo.app.Label;

public class TestGrid extends Grid {

    public TestGrid() {
        size = 2;
        background = Color.BLUE;
        width = new Extent(100, Extent.PERCENT);
        components = [
            new Label(
                text: "Label 1"
            ),
            new Label(
                text: "Label 2"
            ),
            new Label(
                text: "Label 3"
            ),
            new Button(
                text: "Click me",
                actionPerformed: {evt -> println "You clicked me: $evt"}
            )
        ];
    }

}

When you have complex nested UIs, it becomes much easier to read the code when it is expressed in this hierarchical way, rather than flat Java code. Also, if you integrate a groovy script engine, you don't need to restart your server to test changes. This brings many of the benefits of client-side development, as elaborated by Todd in [WWW] this post.

Unfortunately, minor changes are required to echo3 in order to make this work:

The patch supplied on this page facilitates this, and applies cleanly to the latest svn at the time of writing. I am attempting to have this patch incorporated into the core, but I don't yet know if that will be successful.

At the moment, if you use this method, you will also need to patch any other component libraries that you use, such as extras or filetransfer. I will supply patches for those very soon (I have already patched them at work).

Applying the patch

  1. Go to the linked page and save the patch somewhere, e.g. to /home/bob/groovy.patch;

  2. Check out the latest echo3 source and set up the necessary build options (i.e. path to SERVLET_LIB_JAR);

  3. cd into the directory and type patch -p0 < /home/bob/groovy.patch

  4. type ant dist to build the new jars.

Downloading the patches

Echo3GroovyPatches (Warning - the page takes a while to load, since patches are provided inline.

last edited 2008-07-03 20:21:56 by SimonGodden