Dispatch Configurations

The <dispatch> element is used to define a dispatch configuration. It may appear either inside the <dispatches> element to define a global dispatch configuration or inside an <action> element to define a local dispatch configuration.

A dispatch configuration contains information about how to proceed after action invocation. It may either point to another action or to a resource path. It may also specify a custom dispatcher and whether to use redirection.

The <dispatch> element takes the following attributes:

It is an error to specifying both, the action and path attributes. Furthermore, the module attribute is only permitted in conjunction with the action attribute.

The body of the <action> element may contain a set of <param> elements. Dispatchers may use parameters in their own way. However, the default dispatcher will append them as request parameters.

A dispatch configuration is reflected by the DispatchConfig interface, which defines methods to access the attribute values as well as the getParamConfig() method to lookup parameters by name.

The DispatchConfig interface is the result type of the action's execute() method. An action uses its action configuration, ActionConfig, to lookup a dispatch configuration by name, using the

public DispatchConfig findDispatchConfig(String name);

method. The default dispatch configuration can be accessed by specifying name null.

Examples

Dispatching to an action in the current module

<dispatch name="foo" action="/bar"/>

dispatches to action with path="/bar" in the current module.

Dispatching to an action in another module

<dispatch name="foo" module="other" action="/bar"/>

dispatches to action with path="/bar" in the module other.

Dispatching to a context-relative path

<dispatch name="foo" path="/WEB-INF/jsp/bar.jsp"/>

dispatches to JSP at /WEB-INF/jsp/bar.jsp.

Adding parameters

<dispatch name="foo" path="/WEB-INF/jsp/bar.jsp">
  <param name="mode" value="lazy"/>
</dispatch>

dispatches to JSP using request path /WEB-INF/jsp/bar.jsp?mode=lazy.

Using redirection

<dispatch name="foo" path="/jsp/bar.jsp" redirect="true"/>

redirects to JSP at context-relative path /jsp/bar.jsp, whereas

<dispatch name="foo" path="http://calyxo.org" redirect="true"/>

redirects to absolute URL http://calyxo.org.

Using a custom dispatcher

Consider you implemented a custom dispatcher, which wraps the response to capture and buffer its content, before dispatching to a resource producing some XML. Then, it gets the the xml content and and applies an XSL transformation on it. Say, you registered this accessor as "xslt" using a plugin. After all,

<dispatch name="foo" dispatcher="xslt" path="/bar.xml">
  <param name="stylesheet" value="/WEB-INF/xsl/style.xsl"/>
</dispatch/>

will cause your custom dispatcher to apply XSLT stylesheet /WEB-INF/xsl/style.xsl to the content of /bar.xml.