The URL mapping process

This page will describe the URL mapping process. It will cover the way how the controllers are executed and how the view will be generated. The views are handled by velocity templates.

The controller

Since jZonic uses convention over configuration the location of the Controllers are defined by the base package. For now we will assume that the base package is org.jzonic.test. This means that all controllers will be located in the package org.jzonic.test.controller. Every controller needs to extend the AbstractController of jZonic. Here is the shortest controller

import org.jonic.web.AbstractController

public class TestController extends AbstractController {

public String getName() { return "test"; } }

The controller will be automatically detected during startup and will be added to your application. The name of the controller is later used to refer to it. Before we explain the mapping process we will add one method to our controller

public void index() {
}

The URL will no exist of the context name of your application followed by the controller name and then the method

http://localhost:8080/app/test/index.jz

The ending ".jz" is the default setting. You can easily change this in the web.xml file located in the resources directory.

That is the basic principle how the URL is mapped to the executing class. In order to add new URL or page you simply need to add a new method. If you would run this example so far you would only receive an error message since the view is missing

The view

The view part of the framework is handled by velocity templates. Also here the same convetion over configuration is applied. All your templates will be located in the web subdirectory. The template is detected automatically when the request is executed. Basically the framework expects that there is a subdirectory with the name of your controller. In our example there must be a "test" subdirectory. Now for every method that you have in your controller there must be one file with the same name. If we take the example from above the directory will look like this

web/test/index.vm

There is no need for you to define the template or something else in your controller code. It will be done automatically.

Page: UrlMapping last edited by admin on 03/10/2009 11:00 revision: 4
Labels:  (none)    Permalink