After examining the ClickServlet class, I noticed the newPageInstance() method, 
which is where new instances of Page objects are created. By default, 
newPageInstance() calls Class.newInstance() on the given class. This can be 
overridden by subclassing ClickServlet. However, I believe this functionality 
should be factored out into a separate class. A separate page factory would 
allow page objects to be created in more flexible ways (e.g., from Spring 
contexts or Tapestry IoC registries) without altering the ClickServlet. I 
imagine an interface like the following:

interface PageFactoryService {

    void onInit(ServletContext servletContext) throws Exception;

    Page newPageInstance(String path, Class<? extends Page> pageClass, 
HttpServletRequest request) throws Exception;

    void onDestroy();
}

The ConfigService API would be revised to support this new service:

interface ConfigService {
    ...
    PageFactoryService getPageFactoryService();
    ...
}

This interface would have a default implementation, which could be overidden 
with the help of ConfigService. ClickServlet.newInstance() could then delegate 
to this page factory.
                                          

Reply via email to