Skip to content
neoneo edited this page Apr 7, 2012 · 8 revisions

The Context object stores all information about events and makes object instances, such as controllers, available to executing tasks.

All object instances, except Event and Response instances, are 'static', and thus cached by Context. These static objects therefore live as long as the Context object lives. Usually, you would create an instance of Context in onApplicationStart(), but basically it's up to you how you handle Context instances.

Context exposes the following methods:

Response handleRequest()

This is a default request handling implementation, that gathers variables in the url and form scopes, and dispatches the corresponding event. If there are target and event variables present in those scopes, then those variables define the event target and type. If they are not present the default target and default event are used. You can set these using setDefaultTarget() and setDefaultEvent().
The method returns the Response object that contains all generated content.

Response handleEvent(required string, required string, optional struct)

This method starts the event handling routine. You can use this method if handleRequest() doesn't suit your needs, but a better approach is to employ a RequestStrategy.

Arguments:

  1. The target (string)
  2. The event type (string)
  3. Data that is available to the event (struct)

The method returns the Response object that contains all generated content.

register(required Task, required string, required string, optional string)

Registers a Task to be executed for a given target and event, during a given phase. Use this method if you don't want to configure using the default XML dialect.

Arguments:

  1. The Task to be executed
  2. The phase: 'start', 'before', 'after', 'end', or 'event'
  3. The target
  4. The event type: only required for tasks in the 'event' phase

You can create tasks with the factory methods that Context provides, see below. Task is an interface, so you can also create your own specific implementations.

setDefaultTarget(required string)

Sets the default target, used if no target is set explicitly.

setDefaultEvent(required string)

Sets the default event type, used if no event type is set explicitly.

setImplicitTasks(required boolean)

Sets whether to use CFlow conventions if an event is dispatched that is not defined. If false, and such an event is dispatched, nothing happens. Otherwise, when true, two Tasks are created that are then executed.

setControllerMapping(required string)

Sets the (dot delimited) mapping that is used to find controllers. You don't have to set this, you can also provide the complete path in the configuration.

setViewMapping(required string)

Sets the (slash delimited) mapping that is used to find views (.cfm templates). Like the controller mapping, this is optional.

Task createInvokeTask(required string, required string)

Creates an InvokeTask. Arguments:

  1. The controller name. This is combined with the controller mapping to locate the controller component.
  2. The method name to be invoked when this task executes.

Task createDispatchTask(required string, required string, boolean = true)

Creates a DispatchTask. Arguments:

  1. The target name of the event to dispatch.
  2. The event type.
  3. If true, cancels the calling event when the dispatched event is canceled. This is the default.

Clone this wiki locally