Map the root object

The first thing that milton needs is some object to represent the root of your file/folder hierarchy. This is done with the @Root annotation.

Just add this to a method which returns an object representing the root for the given host. In this example we arent using virtual hosting, so the root object doesnt really matter. The simplest thing in this case is just to return the controller itself.

    public HelloWorldController getRoot() {
        return this;

Thats enough to run the application, but it won't say "hello world" yet, so lets do some more.

Lets say our application was a product database, so we had Product objects, and we wanted each Product to be shown as a folder which contains files pertaining to that product.

So we'll add a simple little Product class (in the controller class) to mimic what would be a real domain object, and we'll create 2 products in the constructor

The Product class shown here is only to mimic a domain class in a real business app. You probably wont use inner classes in your app!

    private List<Product> products = new ArrayList<Product>();

    public HelloWorldController() {
        products.add(new Product("hello"));
        products.add(new Product("world"));


    public class Product {
        private String name;

        public Product(String name) {
   = name;


And then we give milton a method that lets it find these are children of the root object:

    public List<Product> getProducts(HelloWorldController root) {
        return products;

OK, thats enough coding, lets run it!