Action Configurations

Actions are configured by <action> elements, which appear inside the <actions> element.

In short, an action configuration may specify a core action implementation, parameters, a sequence of filters, exception handlers and a dispatcher. Each action is associated with a module-relative path.

More concrete, an action configuration may take the following attributes:

  1. The mandatory path giving the module-relative action path. The path must start with a slash ('/'). At most one action may state path="/*", making it the default action. It will be invoked whenever a request did not match any other action path.
  2. The optional class attribute gives the fully qualified class name of the core action command. If the class attribute is omitted, a built in default implementation will answer the dispatch configuration corresponding to the <dispatch> element whose name is referenced by the target attribute.
  3. An optional dispatcher attribute to name a dispatcher to be used for this action. This may be overridden by <dispatch> elements.

The body of the <action> element contains a sequence of one or more

  1. <param> elements to define named action configuration parameters
  2. <filter> elements to add filters to the action's filter chain
  3. <dispatch> elements to define dispatch targets
  4. <exception-handler> elements to define local exception handlers

An action's configuration is reflected by the ActionConfig interface. An object implementing this interface is made available to action, filter and exception handler implementations. Beside methods corresponding one-to-one to an <action> element's attributes and children, the method findDispatchConfig(String) is used to lookup a dispatch configuration by name, consulting local dispatch configurations prior to global dispatch configurations.

Examples

In the Java code snippets in the following examples, config references an instance of ActionConfig.

Simple action

A simple action configuration might look like this:

<action path="/login" class="org.foo.bar.LoginAction">
  <dispatch name="success" action="/welcome"/>
  <dispatch name="failure" path="/WEB-INF/jsp/login.jsp"/>
</action>

Here, we associated path /login with an action. The action's core implementation is given by class org.foo.bar.LoginAction. The action contains two <dispatch> elements: one of these dispatch configurations may be chosen by the action implementation as a result. The first dispatch element says "dispatch to the action (in the same module) associated with path /welcome". The second dispatch element says "dispatch to the context-relative resource path /WEB-INF/jsp/login.jsp".

E.g., an action implementation may choose dispatch success using config.findDispatchConfig("success").

Adding a Parameter

In the following example, we'll add a parameter named users.

<action path="/login" class="org.foo.bar.LoginAction">
  <param name="users" value="/WEB-INF/users.xml"/>
  <dispatch name="success" action="/welcome"/>
  <dispatch name="failure" path="/WEB-INF/jsp/login.jsp"/>
</action>

The action implementation may access this parameter using config.getParamConfig("users").

Using the Default Action

If we omit the class attribute, the default action will be used.

<action path="/login.out">
  <dispatch path="/WEB-INF/jsp/login.jsp"/>
</action>

This action will just dispatch to /WEB-INF/jsp/login.jsp.