RoutingService

Provides the ability to return (and therefore have rendered) an alternative object from an action invocation.

There are two primary use cases:

  • if an action returns an aggregate leaf (that is, a child object which has an owning parent), then the parent object can be * returned instead.

    For example, an action returning OrderItem might instead render the owning Order object. It is the responsibility of the implementation to figure out what the "owning" object might be.

  • if an action returns null or is void, then return some other "useful" object.

    For example, return the home page (eg as defined by the org.apache.causeway.applib.annotation.HomePage annotation).

Currently this service is used only by the Wicket viewer; it is ignored by the Restful Objects viewer.

API

RoutingService.java
interface RoutingService {
  boolean canRoute(Object original)     (1)
  Object route(Object original)     (2)
}
1 canRoute(Object)

whether this implementation recognizes and can "route" the object.

2 route(Object)

The object to route to instead; this may be the same as the original object, some other object, or (indeed) null.

Members

canRoute(Object)

whether this implementation recognizes and can "route" the object.

The #route(Object) method is only called if this method returns true .

route(Object)

The object to route to instead; this may be the same as the original object, some other object, or (indeed) null.

Implementation

The framework provides a default implementation - o.a.c.runtimeservices.routing.RoutingServiceDefault - which will always return the original object provided, or the home page if a null or void was provided. Under the covers this implementation uses the HomePageResolverService.

Usage

Unlike most other domain services, the framework will check all available implementations of RoutingService to return a route, rather than the first implementation found; in other words it uses the chain-of-responsibility pattern.

Services are called in the order defined by the @javax.annotation.Priority annotation. The route used will be the result of the first implementation checked that declares that it can provide a route.

  • HomePageResolverService

    Used by the default implementation of this service uses the to determine where to route actions that return null or are declared as void.