1.0          Other languages
 
 

3.3.5 Web request dispatcher URL management

 
 

In VelocityWeb, URL is always like http://<server_ip>:<server:port>/<web_app_name>/<url_mapping_path>/ControllerServlet?m1=system&m2=store_main

In this URL, the last part

?m1=system&m2=store_main

is managed by URL manager in VelocityWeb. To build this URL, first, we need to register "system" to root URL depository.

public class PetStoreController extends SimpleController {
    ...
    public boolean initApplication() {
	    ...
        // add system dispatchers
        DispatcherTreeManager.addToRoot(SystemDispatcherGroup.class);
	  

And the "m1=system" stands for SystemDispatcherGroup, "m2=store_main" stands for StoreMainDispatcher.

public class SystemDispatcherGroup extends DispatcherGroup {
    static{
        DispatcherTreeManager.addParentChildrenRelationship(SystemDispatcherGroup.class, StoreMainDispatcher.class);
    }
    
    public SystemDispatcherGroup() {
        this.setPageLayout(new VPetStorePageLayout());
    }

    public String getUrlId() {
        return "system";
    }

}

public class StoreMainDispatcher extends QueryDispatcher {
    public String getUrlId() {
        return "store_main";
    }
    public StoreMainDispatcher() {
this.setHtmlTemplateFileName("system/store_main.htm");
this.setPageTitle("Default Store Home");
} ...

In this way, this kind of URL can stand for LeafDispatcher and DispatcherGroup.

        Root
           |
           |____SystemDispatcherGroup(system)
                                 |
                                 |____StoreMainDispatcher(store_main)
	  

The max level of this tree in VelocityWeb is unlimited. That means you can create your URL like
?m1=xx&m2=xx&m3=xx&...&m1000=xx

In most application, the URL tree level is less than five.

The reason why we don't use the XML file to mapping URL id to dispatcher class is that, when we use single XML file to manage this relationship, it's hard for more than one programmers to concurrent maintain this configuration file. Good design should avoid many programmers modify same file continuously during whole coding phase.

VelocityWeb try to avoid concentrative configuration. As we can see in above code, StoreMainDispatcher specify it's own view HTML page and URL ID inside it. Other dispatcher will do the same thing too. This can avoid one file been concurrent modied by programmers. Because the possibility of concurrent modifying a application level configuration file is more bigger than modifying a request dispatcher class.