Sunday, July 27, 2008

about MasterDispatcher of Tapestry5

在tapestry5中dispatcher是按顺序进行请求分发的,这样才能正确区分请求,而不会使分发器发生混淆,如一个url为:/assets/tapestry5/tapestry.js,这个看上去也像是一个组件请求(for page "assets/tapestry5/tapestry" and component "js"),因此需要确保AssetDispatcher分发器在ComponentAction分发器之前被检查,如果此分发器检查后返回true,则会执行到此分发器为止,返回false则继续执行下一个分发器的检查(参考TapestryModule原代码如下)。
The MasterDispatcher is a chain-of-command of individual Dispatchers, each handling (like a servlet) a particular kind of incoming request.

* RootPath
* Renders the start page for the "/" request
* Asset
* Provides access to classpath assets
* PageRender
* Identifies the PageRenderRequestParameters and forwards onto PageRenderRequestHandler
* ComponentEvent
* Identifies the ComponentEventRequestParameters and forwards onto the ComponentEventRequestHandler
public void contributeMasterDispatcher(OrderedConfiguration configuration,
ObjectLocator locator)
// Looks for the root path and renders the start page. This is maintained for compatibility
// with earlier versions of Tapestry 5, it is recommended that an Index page be used instead.


// This goes first because an asset to be streamed may have an file extension, such as
// ".html", that will confuse the later dispatchers.

locator.autobuild(AssetDispatcher.class), "before:ComponentEvent");

configuration.add("ComponentEvent", locator.autobuild(ComponentEventDispatcher.class),


No comments :